RE: Getting key value with an insert and using it in another. - Mailing list pgsql-general

From Dave Cramer
Subject RE: Getting key value with an insert and using it in another.
Date
Msg-id 008201c1139f$b220b3e0$8201a8c0@inspiron
Whole thread Raw
In response to Getting key value with an insert and using it in another.  ("stefan" <stefan@studioweb.com>)
List 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@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of stefan
Sent: July 16, 2001 1:06 PM
To: pgsql-general@postgresql.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@postgresql.org)



pgsql-general by date:

Previous
From: "Mitch Vincent"
Date:
Subject: Re: pqReadData() -- backend closed the channel unexpectedly.
Next
From: teg@redhat.com (Trond Eivind Glomsrød)
Date:
Subject: Re: AutoStart and AutoDown