Skip site navigation (1) Skip section navigation (2)

Re: get id of insert in plpgsql function

From: "A B" <gentosaker(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: get id of insert in plpgsql function
Date: 2008-05-22 14:23:37
Message-ID: dbbf25900805220723o79889a5awaa01746f5552fe30@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Sorry, I found it.
mytable_pkey is not a sequence, it should be mytable_userid_seq.
But still, is there a way to get more clever error reports?


2008/5/22 A B <gentosaker(at)gmail(dot)com>:
> 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?
>

In response to

pgsql-novice by date

Next:From: guillaume.yziquelDate: 2008-05-22 17:14:04
Subject: How to connect to the database server
Previous:From: A BDate: 2008-05-22 14:16:25
Subject: Re: get id of insert in plpgsql function

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group