Postgresql 带变量的postgres SQL函数
谁能告诉我为什么不在表中插入这个函数Postgresql 带变量的postgres SQL函数,postgresql,Postgresql,谁能告诉我为什么不在表中插入这个函数 CREATE OR REPLACE FUNCTION insert_one(_temp VARCHAR(1000)) RETURNS void AS $$ DECLARE TEMP INT := NULL; BEGIN SELECT "temptable"."id" INTO TEMP FROM "temptable" WHERE "tmpstr" = _temp; IF TEMP IS NULL THEN INSER
CREATE OR REPLACE FUNCTION insert_one(_temp VARCHAR(1000))
RETURNS void AS $$
DECLARE
TEMP INT := NULL;
BEGIN
SELECT "temptable"."id" INTO TEMP FROM "temptable" WHERE "tmpstr" = _temp;
IF TEMP IS NULL THEN
INSERT INTO "temptable"("tmpstr") values(_temp);
SELECT CURRVAL("id") FROM "temptable" INTO TEMP;
END IF;
END;
$$ LANGUAGE plpgsql;
您可能会遇到错误,因为没有名为
id
的序列
您可能正在寻找
INSERT INTO temptable (tmpstr)
VALUES (_temp)
ON CONFLICT DO NOTHING
RETURNING id;
您可能会遇到错误,因为没有名为
id
的序列
您可能正在寻找
INSERT INTO temptable (tmpstr)
VALUES (_temp)
ON CONFLICT DO NOTHING
RETURNING id;