Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 带变量的postgres SQL函数_Postgresql - Fatal编程技术网

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;