0

Can anyone tell me why does not insert this function anything into the table?

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;

1 Answer 1

2

You probably get an error because there is no sequence called id.

You are probably looking for

INSERT INTO temptable (tmpstr)
   VALUES (_temp)
ON CONFLICT DO NOTHING
RETURNING id;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.