Re: currval() - Mailing list pgsql-admin

From Steve Crawford
Subject Re: currval()
Date
Msg-id 4E7927BD.50404@pinpointresearch.com
Whole thread Raw
In response to currval()  (Marc Fromm <Marc.Fromm@wwu.edu>)
List pgsql-admin
On 09/20/2011 04:06 PM, Marc Fromm wrote:

My postgres version is 8.1. Last I heard RETURNING id started in 8.2.

I'd advise upgrading. 8.1 is no-longer supported (end-of-life was last November) and 8.2 has an end-of-life date in just a couple months. You'll get security and bug fixes, performance benefits and, of course, those cool new features you need. :)

(No security fixes is often the issue that gets management attention if necessary.)

Is not my semicolon before the select statement make it two sequential staements?

I don’t get an sql error when it is executed.


Well, it is technically legal (and why SQL injection can work). Looks like you are using PHP and PHP says that if you bundle statements together they will be executed as a transaction.

Perhaps it's personal preference, but combining statements like that is difficult to read and I suspect will make bugs hard to find. And although I can't find it documented, it appears that the return value is only from the final statement. I shy away from undocumented behaviour and I'd rather be able to check the result of each statement.

 

I did learn from another reply that my select statement was wrong. I needed to SELECT currval('jobs_id_seq') not the field name, which I was doing.


Yes, this is probably the real root of your problem. I did not notice that since I didn't have the table definition in front of me.

Cheers,
Steve

pgsql-admin by date:

Previous
From: Steve Crawford
Date:
Subject: Re: currval()
Next
From: Rural Hunter
Date:
Subject: Re: Warm standby terminate itself?