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

From: Scott Chapman <scott_list(at)mischko(dot)com>
To: Doug McNaught <doug(at)mcnaught(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL-question: returning the id of an insert querry
Date: 2003-11-12 19:46:44
Message-ID: 200311121146.44509.scott_list@mischko.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wednesday 12 November 2003 11:29, Doug McNaught wrote:
> Scott Chapman <scott_list(at)mischko(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christopher Murtagh 2003-11-12 20:05:34 pl/perl function life and variable scope - concurrency problem?
Previous Message Paul Thomas 2003-11-12 19:44:34 Re: RHEL