Re: SQL Help - Obtaining ID of record INSERTED

From: Ben Kim <bkim(at)coe(dot)tamu(dot)edu>
To: "josh(at)segrestfarms(dot)com" <josh(at)segrestfarms(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: SQL Help - Obtaining ID of record INSERTED
Date: 2005-08-16 22:57:52
Message-ID: Pine.GSO.4.10.10508161748100.16844-100000@coe.tamu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin


You got the suggestion using currval already so here's one alternative.

SELECT NEXTVAL('"orderid_sequence_name"');

Assume this value is $val then do

INSERT INTO orderstemp(orderid,...) VALUES ($val, ...);

I'm not sure if this is generally used, but this works and sometimes this
way is convenient for batch processing.

>SELECT @@identity as orderid

My 0.02$.

Regards,

Ben Kim
Developer
College of Education
Texas A&M University

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Andrew Gold 2005-08-16 23:07:52 GRANT ALL PRIVILEGES ON DATABASE
Previous Message Tom Lane 2005-08-16 22:42:01 Re: Restore from pg_dumpall