Getting key value with an insert and using it in another. 
Author Message
 Getting key value with an insert and using it in another.

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

Quote:
-----Original Message-----


Sent: July 16, 2001 1:06 PM

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.


anything?

Thanks,

Stefan

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate

message can get through to the mailing list cleanly



Sat, 10 Jan 2004 04:18:31 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. Getting the next available key value for a table and insert a new record

2. Getting the next available key value for a table and insert a new record

3. Getting primary key value after insert

4. Getting key field value after insert

5. Getting Back Identity column value on Insert using RDS

6. Determining the value of a just-inserted auto-generated key using JDBC

7. Trigger on Insert / Getting Newly Inserted Primary Key

8. Inserting Null values using Bulk Insert

9. Getting min primary key value

10. Getting (Key Field) Value

11. Getting the Primary Key value


 
Powered by phpBB® Forum Software