Re: currval()

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Marc Fromm <Marc(dot)Fromm(at)wwu(dot)edu>
Cc: "pgsql-admin(at)postgresql(dot)org Admin" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: currval()
Date: 2011-09-20 23:54:37
Message-ID: 4E7927BD.50404@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Rural Hunter 2011-09-21 01:23:59 Re: Warm standby terminate itself?
Previous Message Steve Crawford 2011-09-20 22:52:48 Re: currval()