PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹37. PL/pgSQL - SQL 誺䘋臺蘔媆誕嬉誕

37.5. 臘膆嚟

欔橬婘 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_outtimestamp_in 檪認婻庖严婾蘸扵潊 timestamp 䌂傋䔇埻麟㔗啹溴螇䞖庺䔇施潿儌嚔毬䙓䘋废叻婯橕䔇闼湙婘懟渇欓臯䔇施唍鄘敘桄㔗

螄嘘埻麟䔇滷埻攓婘認䓉䂷劽婪柊庺庖婔婻閞鵻㔗嘷婔婻螄嘘埻麟婘臺埖潡蔙臘膆嚟婺嘪䫘施臖庖枕䔇昄扞䌂傋婘劯婔婻臘膆嚟䔇婉劯脄䫘橘閘婉脘媞櫹啹婺臖臘膆嚟庖崺嘪䫘䔇滇誊臯丸婔渇彄膆臖臘膆嚟施庺䯄䔇昄扞䌂傋㔗婘喍崇䊖崔婻臘䔇庋傽䔇蓥埏単誺䘋䔇施唍婔垔襕檪認婻螄嘟㔗媙襕施埇傖䫘 EXECUTE 䂘嚔認婻閞鵻㔗


劯锔饡釕嬉誕
弄滯婪婔亓嘺橸臺埖