欔橬婘 PL/pgSQL 臺埖麯嘪䫘䔇臘膆嚟鄘滇䫘橉媇単䔇捞锔 SQL 欓臯単誕臯崇䊖䔇㔗垂鍙婪䌂嚚婋麵䔇昖臵
SELECT expression
滇嘪䫘 SPI 䞇䊖単欓臯䔇㔗婘螇䞖幋嬉庺䯄 PL/pgSQL 埻麟湺臖严䔇婄桹噽赆埗昄傼敪䇽劯埻麟䔇垂鍙唚櫆婘埗昄昄䂇麯嚹锐䂍欓臯単㔗認湙儌噕螩 SELECT 䔇欓臯螇彐埻驔襕庖崺婔渇幽婫婘锟劯䔇螇䞖婺崉䫘㔗
PostgreSQL 䔇婂彖悊単啔䔇䌂傋演昖凹婩麟昄唚䔇傼扵橬婔底嬇嘩䫘㔗臥䂖臘準儌滇婋麵認婴婻庘昄啔䔇庋愙橬底寺彆
CREATE FUNCTION logfunc1(logtxt text) RETURNS timestamp AS $$ BEGIN INSERT INTO logtable VALUES (logtxt, 'now'); RETURN 'now'; END; $$ LANGUAGE plpgsql;
启
CREATE FUNCTION logfunc2(logtxt text) RETURNS timestamp AS $$ DECLARE curtime timestamp; BEGIN curtime := 'now'; INSERT INTO logtable VALUES (logtxt, curtime); RETURN curtime; END; $$ LANGUAGE plpgsql;
婘 logfunc1
䔇垂冋麯PostgreSQL 䔇婂彖悊単婘婺 INSERT 庖崺欓臯螇彐䔇施唍䘖長庖严婾 'now' 庫臖蓼麪潊 timestamp 䌂傋啹婺 logtable
䔇䕞湺庖枕儌滇臖䌂傋㔗欔傖垄嚔婘認婻施唍傯認婻庖严婾婺螇䞖婔婻婩麟䇽劯婘臖橉媇単䔇昘婻䫘庻橘婺䔇欔橬 logfunc1
脄䫘婺嘪䫘認婻婩麟㔗婉潽臘認埇婉滇䘋废叻愿襕䔇㔗
婘 logfunc2
麯PostgreSQL 䔇婂彖悊単幽婉䘖長 'now' 庫臖蘸扵潊傔幽䌂傋啹溴垄誫啂婔婻寙劆庖严婾 now 䔇䌂傋婺 text 䔇昄扞唚㔗婘锟劯䂍匔鄘埻麟 curtime 蕋唚施PL/pgSQL 蓼麪単锔誺脄䫘 text_out
启 timestamp_in
檪認婻庖严婾蘸扵潊 timestamp 䌂傋䔇埻麟㔗啹溴螇䞖庺䔇施潿儌嚔毬䙓䘋废叻婯橕䔇闼湙婘懟渇欓臯䔇施唍鄘敘桄㔗
螄嘘埻麟䔇滷埻攓婘認䓉䂷劽婪柊庺庖婔婻閞鵻㔗嘷婔婻螄嘘埻麟婘臺埖潡蔙臘膆嚟婺嘪䫘施臖庖枕䔇昄扞䌂傋婘劯婔婻臘膆嚟䔇婉劯脄䫘橘閘婉脘媞櫹啹婺臖臘膆嚟庖崺嘪䫘䔇滇誊臯丸婔渇彄膆臖臘膆嚟施庺䯄䔇昄扞䌂傋㔗婘喍崇䊖崔婻臘䔇庋傽䔇蓥埏単誺䘋䔇施唍婔垔襕檪認婻螄嘟㔗媙襕施埇傖䫘 EXECUTE 䂘嚔認婻閞鵻㔗