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

Поиск
Список
Период
Сортировка
От Dave Cramer
Тема RE: Getting key value with an insert and using it in another.
Дата
Msg-id 008201c1139f$b220b3e0$8201a8c0@inspiron
обсуждение исходный текст
Ответ на Getting key value with an insert and using it in another.  ("stefan" <stefan@studioweb.com>)
Список 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 по дате отправления:

Предыдущее
От: "Mitch Vincent"
Дата:
Сообщение: Re: pqReadData() -- backend closed the channel unexpectedly.
Следующее
От: teg@redhat.com (Trond Eivind Glomsrød)
Дата:
Сообщение: Re: AutoStart and AutoDown