RE: Getting key value with an insert and using it in another.

From: "Dave Cramer" <Dave(at)micro-automation(dot)net>
To: "'stefan'" <stefan(at)studioweb(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: RE: Getting key value with an insert and using it in another.
Date: 2001-07-23 17:48:34
Message-ID: 008201c1139f$b220b3e0$8201a8c0@inspiron
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yes, they are called sequences in postgres.

Create table tablename (id serial, .... )

This creates a sequence named tablename_id_seq

You can then do a select on

Select next('tablename_id_seq')

Which will give you the next sequence and increment it

Dave

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of stefan
Sent: July 16, 2001 1:06 PM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] Getting key value with an insert and using it in
another.

Hi:

I need to be able to grab a key value generated by the server so that I
can use it with other inserts within the context of a transaction.

In a nut shell, I have an order table and an order details table. When
an order is saved, it has to go into both the order table and the order
detail tables where the order details records require the key value
created in the order table.

SQL server had a function to do this (@@identity) does PostGresSql have
anything?

Thanks,

Stefan

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Keith Irwin 2001-07-23 18:04:00 Re: Does dropping a column from a table mess up foreign keys?
Previous Message Lamar Owen 2001-07-23 17:26:26 Re: AutoStart and AutoDown