我想創建一個函數來更新表。INSERT EXECUTE FORMAT Postgresql字符串
我試圖運行它:
SELECT insert_function('asda', 1 ,1 , 'asd', 1)
但我得到的錯誤:
LINE 3 VALUES("asda","1","1","asd","1") column doesn't exist.
當我試圖腐運行:
SELECT insert_function('1', 1 ,1 , '1', 1)
zero-length delimited identifier at near """""""LINE 3 VALUES(""1"","1","1",""1"","1") (^at the first item)
CREATE TABLE IF NOT EXISTS commits (
id SERIAL PRIMARY KEY,
goo CHAR(64) NOT NULL,
foo INTEGER NOT NULL,
bla INTEGER NOT NULL,
ma CHAR(512) NOT NULL,
fgt INTEGER NOT NULL
);
CREATE OR REPLACE FUNCTION insert_function(goo char(64), foo INTEGER, bla INTEGER, ma CHAR(512), fgt INTEGER)
RETURNS VOID AS
$func$
BEGIN
EXECUTE format('
INSERT INTO commits
VALUES(%I, %I, %I, %I, %I)',
goo , foo , bla , ma , fgt);
END
$func$ LANGUAGE plpgsql;
你能請告訴我如何插入值?我如何使用EXECUTE format
編寫函數?
@ user565447檢查更新 – lad2025