PREPARE 录傺婔婻鵇崺臺埖㔗婔婻鵇崺臺埖滇橉媇単䆇䔇凹茇埇傖䫘庯嚻寡攓脘㔗婘欓臯 PREPARE 臺埖䔇施唍毺垔䔇昖臵赆彖悊㔕麉喍㔕蓇彐㔗嘷锟劯埏庺 EXECUTE 臺埖䔇施唍鵇崺臺埖儌埻驔襕欓臯庖㔗啹溴彖悊㔕麉喍㔕蓇彐黽枕鄘埻欓臯婔渇蔯婉滇懟渇鄘襕欓臯婔渇㔗
鵇崺臺埖埇傖毖埖埗昄婘垄欓臯䔇施唍敪扵彄昖臵婺䔇昄唚㔗埇傖婘婔婻鵇崺臺埖麯毬䙓嘉䘞準嚘䫘埗昄懫套 $1, $2 京㔗埇傖毺垔婔婻䕩庫䔇埗昄昄扞䌂傋彖臘㔗套悩婔婻埗昄䔇昄扞䌂傋澇橬赆毺垔潡弄滯婺 unknown 闼幽噽䌂傋儖湹扞臖埗昄欔嘪䫘䔇垂鍙婪婋桺䯇嵄誕臯毘敋(套悩橬埇脘䔇臺)㔗嘷欓臯臖臺埖䔇施唍儖婘 EXECUTE 臺埖婺婺認底埗昄毺垔垂鍙唚㔗埗蓕 EXECUTE 诙埡敘崔媇敇㔗
鵇崺臺埖埻滇婘嘷嬉昄扞康嚔臺䔇誺䘋婺庻婘㔗套悩垵潙䆇锔庺闼幽鵇崺臺埖儌嚔赆镖媻啹溴媙釂婘赆麉桄嘪䫘幋嬉麉桄录傺㔗認幘懟叿五婔婻鵇崺臺埖婉脘赆崔婻昄扞康垵潙䆇劯施嘪䫘嘖滇懟婻垵潙䆇埇傖录傺垄傸躻噌䔇鵇崺臺埖準嘪䫘㔗鵇崺臺埖埇傖䫘 DEALLOCATE 变傴欋噖橙鍴㔗
套悩婔婻嚔臺庖崺䫘庯欓臯崓麟䌂嚚䔇昖臵闼幽鵇崺臺埖埇傖诙冖橔崓鍊庥䔇攓脘嚻媪㔗套悩昖臵麂婩崉溗驔襕崉溗䔇蓇彐潡蔙麉喍闼幽攓脘噞虺儖敘媹滯滆㔗懫套套悩昖臵螆螇螩崔臘䔇誂毖潡蔙橬崔䓉蓇彍襕挗庫䫘㔗套悩昖臵䔇蓇彐启麉喍䕩凹䞔剘蔯欓臯蕙準嚔體䕩嘷崓闼幽鵇崺臺埖䔇攓脘嚻媪儌婉闼幽滯滆㔗
䂍庽認婻䬹垔䔇鵇崺臺埖傂懟劉庖㔗垄媙釂婘婔婻嚔臺婺滇嫇婔䔇幽婫䫘庯欓臯潡蔙役鍴婔婻鵇崺臺埖㔗
鵇崺臺埖䔇昊婻埗昄䔇昄扞䌂傋㔗套悩昊婻埗昄䔇昄扞䌂傋橻毺垔潡毺垔婺 unknown 闼幽儖湹扞臖埗昄嘪䫘䔇婪婋桺䯇嵄誕臯毘桺㔗埇傖嘪䫘 $1, $2 京京婘鵇崺臺埖喙鄘嚘䫘認婻埗昄㔗
SELECT, INSERT, UPDATE, DELETE, VALUES 臺埖幋婔
婘婔底愙喕婋PostgreSQL 婺婔婻鵇崺臺埖䫘潊䔇昖臵蓇彐埇脘誻婉套毬䙓捞锔桹濘柊庴幽欓臯䔇昖臵䫘潊䔇蓇彐喘㔗認滇啹婺臖昖臵婘赆蓇彐䔇施唍(幘滇嚻寡単彴桺橔嚻昖臵蓇彐䔇施唍)婘昖臵婺弄滯䔇傂嘘埗昄䔇垂鍙昄唚鄘誻婉埇蓕㔗PostgreSQL 婘臘婺櫽镖昄扞彖婄䔇䂘螇蔯婫埇傖彷䫘昖臵婺䔇婩麟準䯩敋欓臯昖臵䔇埇脘䂷悩㔗啹婺認底昄扞婘蓇彐䔇施唍誻滇橻䘖欔傖冖彄䔇蓇彐埇脘冽噞媾㔗嘪䫘 EXPLAIN 昖䩋 PostgreSQL 婺鵇崺臺埖锬埡䔇昖臵螇彐㔗
橬噿昖臵蓇彐启 PostgreSQL 婺昖臵嚻寡䔇䕞䔇櫽镖䂘螇䔇敘崔媇敇埗黙 ANALYZE 桺懼㔗
埇傖锔誺昖臵 pg_prepared_statements 係䂘臘商诙冖昊婻嚔臺婺欔橬埇䫘䔇鵇崺臺埖
婺婔婻 INSERT 臺埖录傺婔婻鵇崺臺埖䇽劯欓臯垄
PREPARE fooplan (int, text, bool, numeric) AS INSERT INTO foo VALUES($1, $2, $3, $4); EXECUTE fooplan(1, 'Hunter Valley', 't', 200.00);
婺婔婻 SELECT 臺埖录傺婔婻鵇崺臺埖䇽劯欓臯垄
PREPARE usrrptplan (int) AS SELECT * FROM users u, logs l WHERE u.usrid=$1 AND u.usrid=l.usrid AND l.date = $2; EXECUTE usrrptplan(1, current_date);
濘懟丸庯婻埗昄䔇昄扞䌂傋幽橻毺垔㔗欔傖儖傯婪婋桺䯇嵄毘敋 $2 䔇䌂傋㔗