Re: SQL-question: returning the id of an insert querry

Scott Chapman <scott_list@mischko.com>

From: Scott Chapman <scott_list@mischko.com>
To: Doug McNaught <doug@mcnaught.org>
Cc: pgsql-general@postgresql.org
Date: 2003-11-12T19:46:44Z
Lists: pgsql-general
On Wednesday 12 November 2003 11:29, Doug McNaught wrote:
> Scott Chapman <scott_list@mischko.com> writes:
> > It would be nice if PostgreSQL could return the primary key it
> > inserted with but that may not be a fool-proof solution either.  Is
> > there a nice way to handle this situation?
>
> Write a database function that inserts the record and returns the
> primary key value?  That's probably the best way to insulate your app
> from the database structure...

The function still has to know which sequence to pull from doesn't it?

I don't know much about triggers/functions in PG.  Is it possible to 
have a function that intercepts the information AFTER the sequence 
value is added as the new primary key and then return it?  This would 
enable the use of a more generic function.

Scott