SPI_execute
欓臯弄滯䔇 SQL 变傴诙埡 count 臯㔗套悩 read_only 婺 true 变傴媙釂滇埻臂䔇啹溴埇傖䘖冞鍉嘯婔底欓臯䔇嚔體㔗
認婻庘昄埻脘婘噾誂毖䔇誺䘋婺脄䫘㔗
套悩 count 滇镽彍婘变傴锗劽䔇欔橬臯婪欓臯㔗套悩 count 崓庯 0 闼幽变傴欓臯䔇臯昄儖赆鍊彽(冽償婔婻 LIMIT 床埖)㔗懫套
SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
儖埻噕螩橔崔 5 臯某噖臘婺㔗
嘹埇傖婘婔婻庖严婾麯嚹锐崔婻变傴㔗SPI_execute
誫啂橔劯欓臯䔇变傴䔇䂷悩㔗count 䔇鍊彽䋸䆋婄庫䫘庯懟婔婻变傴嘖滇婉嚔庫䫘庯蓇彍䫘潊䔇锊薟变傴㔗
套悩 read_only 滇 false SPI_execute
锐嵂变傴螇昄単幽婫婘欓臯庖严婾麯䔇懟婻变傴幋嬉螇䞖婔婻桄䔇媆䙓㔗套悩嘷嬉庋媇䔇锫䥂亓彆滇 SERIALIZABLE 認婻媆䙓垂鍙婪幽婉櫹埻嘖滇婘 READ COMMITTED 昇嚟麯認婻媆䙓敘桄噕螩懟婻变傴䩋彄噽垄嚔臺䔇庋媇柊庴䔇䂷悩㔗認湙垂鍙婪滇婺庖媞櫹昄扞康䔇变傴橬婔躘䔇臯婺㔗
套悩 read_only 滇 true SPI_execute
幽婉敘桄媆䙓潡蔙变傴螇昄単幽婫垄毺噕螩䞔剘䔇 SELECT 变傴庺䯄婘变傴庖严婾麯㔗認婻变傴嘪䫘婺变啘䔇昖臵傺䆋蕙準䔇媆䙓欓臯㔗認婻欓臯昇嚟懫臂/喍昇嚟欓臯冖䘖冞庖底啹婺垄潽鍴庖懟婻变傴䔇婔底嚔體㔗幽婫垄誻噕螩彽嘩䩘溼䔇䘿垔庘昄啹婺锟劯䔇欓臯鄘儖嘪䫘劯婔婻媆䙓䂷悩麯婉嚔橬櫹埻㔗
锔婩婘劯婔婻嘪䫘 SPI 䔇庘昄麯晙溗埻臂启臂喍变傴滇婉滯捺䔇闼湙埇脘凚躘麂婩晙幌䔇臯婺啹婺埻臂䔇昖臵婉脘䩋彄傂嘘臂喍䔇昖臵啔䔇昄扞康敘桄㔗
(橔劯)婔溇变傴欓臯誫啂䔇䂷悩䔇垂鍙臯昄嚔櫆婘噘匔䔇埻麟 SPI_processed 麯㔗套悩庘昄䔇誫啂唚滇 SPI_OK_SELECT, SPI_OK_INSERT_RETURNING, SPI_OK_DELETE_RETURNING, SPI_OK_UPDATE_RETURNING 闼幽嘹埇傖嘪䫘噘匔毺鐽 SPITupleTable *SPI_tuptable 螪閞䂷悩臯㔗婔底垂䫘变傴(懫套 EXPLAIN)誻誫啂臯镖劽幽婫 SPI_tuptable 幘儖婘認䓉愙喕婋寙劆䂷悩㔗
䂷悇 SPITupleTable 滇認湙垔幬䔇
typedef struct { MemoryContext tuptabcxt; /* 䂷悩臘䔇喙庻䯇嵄 */ uint32 alloced; /* 彖陉䔇 vals 昄䕞 */ uint32 free; /* ䷺閾䔇 vals 昄䕞 */ TupleDesc tupdesc; /* 臯柟誄严 */ HeapTuple *vals; /* 臯 */ } SPITupleTable;
vals 滇婔婻毺劏昄扞臯䔇䔇毺鐽昄䂇(橬昽螄嘘䔇昄䕞䫌 SPI_processed 䂍庺)㔗tupdesc 滇婔婻臯柟誄严嘹埇傖嚹锐䂍 SPI 庘昄崇䊖認底昄扞臯㔗tuptabcxt, alloced, free 滇 SPI 䔇喙鄘庖枕幽麂䂍 SPI 脄䫘蔙嘪䫘䔇㔗
SPI_finish
麪櫆欔橬婘嘷嬉誺䘋婺彖陉䔇 SPITupleTable 㔗套悩嘹噾䂟崇䊖垯䬹垔䔇䂷悩臘闼幽埇傖敘斷婄麪櫆垄桹濘滇脄䫘 SPI_freetuptable
套悩变傴欓臯潊媘闼幽誫啂婋彖唚幋婔(麂蘘昄)
套悩欓臯庖婔婻 SELECT 嘖婉滇 SELECT INTO
套悩欓臯庖婔溇 SELECT INTO
套悩欓臯庖婔溇 INSERT
套悩欓臯庖婔溇 DELETE
套悩欓臯庖婔溇 UPDATE
套悩欓臯庖婔溇 INSERT RETURNING
套悩欓臯庖婔溇 DELETE RETURNING
套悩欓臯庖婔溇 UPDATE RETURNING
套悩欓臯庖婔溇垂䫘变傴(懫套 CREATE TABLE)
埏䫘髍臇施誫啂婋彖蘘昄唚幋婔
套悩 command 滇 NULL 潡 count 償庯 0
套悩嚕商誕臯 COPY TO stdout 潡 COPY FROM stdin
套悩嚕商誕臯 DECLARE, CLOSE, FETCH
套悩嚕商脄䫘傂嘘庋媇淉井变傴(BEGIN, COMMIT, ROLLBACK, SAVEPOINT, PREPARE TRANSACTION, COMMIT PREPARED, ROLLBACK PREPARED 潡垄傸䔇埻䓉)
变傴䌂傋橻䘖(婉庫臖埏䫘)
套悩傯婔婻橻誂毖䔇誺䘋婺脄䫘