Re: get id of insert in plpgsql function - Mailing list pgsql-novice

From A B
Subject Re: get id of insert in plpgsql function
Date
Msg-id dbbf25900805220716n44defd34ibbea3e0499f60d01@mail.gmail.com
Whole thread Raw
In response to get id of insert in plpgsql function  ("A B" <gentosaker@gmail.com>)
Responses Re: get id of insert in plpgsql function  ("A B" <gentosaker@gmail.com>)
List pgsql-novice
I think I managed to get it working, but the error reporting is not so good,

Here is the function (I removed some stuff to make it shorter)

CREATE OR REPLACE FUNCTION addB(userid_ integer) RETURNS INTEGER AS $$
DECLARE
    bibid INTEGER;
BEGIN
    BEGIN
    INSERT INTO mytable (userid,y) VALUES (userid_,'f') RETURNING
currval('mytable_pkey') into bibid;
        RETURN bibid;
    EXCEPTION WHEN OTHERS THEN /*Catch all*/
        RETURN 0;
    END;
END;
$$ LANGUAGE plpgsql;

Now, I had forgot to add the column 'y' to mytable, and I got the error message

ERROR:  syntax error at or near "Resource" at character 1
STATEMENT:  Resource id #23

in the  pg_log/logfile
Is there clever setting to get a better response?

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: recreating tables from global files
Next
From: "A B"
Date:
Subject: Re: get id of insert in plpgsql function