Re: Seral field value after INSERT !
От | Gregory Wood |
---|---|
Тема | Re: Seral field value after INSERT ! |
Дата | |
Msg-id | 00f601c0ce5d$e29af3a0$7889ffcc@comstock.com обсуждение исходный текст |
Ответ на | Seral field value after INSERT ! (Berényi Gábor <Berenyi.Gabor@posta.hu>) |
Список | pgsql-general |
> I have been inserting records into a table using the SQL insert statement. > One of the field types is serial, and I have been > trying to figure out how to get the value that was assigned in the field as > a result of the insert. The serial typed field is the only one guaranteed > to be unique, so I can't really do a search, and there are several people > adding data at once, so I can't reliable guess. Can anyone help? You can get the serial value by doing a SELECT currval('SeqName'); after performing the insert. That value will be correct for the last INSERT performed *by that backend*. This means that if each of those people are adding data at once, one particular person will see only the last value that that person inserted regardless of what the actual last value inserted was. The SeqName for a serial is usually just <TableName>_<SerialField>_SEQ. There is a character limit, so if you have really long field table/field names, you might have to look at the system catalogs. Greg
В списке pgsql-general по дате отправления: