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

Re: [NOVICE] Last ID Problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Mark Cave-Ayland" <m(dot)cave-ayland(at)webbased(dot)co(dot)uk>
Cc: "'Alvaro Herrera'" <alvherre(at)dcc(dot)uchile(dot)cl>,"'Michael Fuhr'" <mike(at)fuhr(dot)org>,"'Mitch Pirtle'" <mitch(dot)pirtle(at)gmail(dot)com>,"'Tatsuo Ishii'" <t-ishii(at)sra(dot)co(dot)jp>, pgsql-hackers(at)postgresql(dot)org,operationsengineer1(at)yahoo(dot)com
Subject: Re: [NOVICE] Last ID Problem
Date: 2005-02-02 15:34:40
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
"Mark Cave-Ayland" <m(dot)cave-ayland(at)webbased(dot)co(dot)uk> writes:
> Just off the top of my head, would it not be feasible to add a column to
> pg_class called lastinsert that points to the OID of the pg_attribute column
> to return after an insert?

No.  The thing everyone is ignoring here is that the INSERT command tag
format is not something we can just go and change.  You certainly could
not put anything in it that wasn't an integer, and I'm not sure it would
even be safe to put a bigint.  So most of the cases you might actually
want (timestamp, bigserial, etc) would be ruled out.  Hardly worth
inventing such a feature.

> I see that INSERT...RETURNING is a solution to the problem, but it seems
> somewhat strange to have to use an unportable command just to be able to
> return an identifier for the last inserted record...

How is what you're suggesting more portable?

			regards, tom lane

In response to


pgsql-hackers by date

Next:From: Tom LaneDate: 2005-02-02 16:07:54
Subject: Re: libpq API incompatibility between 7.4 and 8.0
Previous:From: a_ogawaDate: 2005-02-02 15:07:09
Subject: Re: FunctionCallN improvement.

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