Re: List sequence assigned to primary key
| От | Henshall, Stuart - Design & Print |
|---|---|
| Тема | Re: List sequence assigned to primary key |
| Дата | |
| Msg-id | E2870D8CE1CCD311BAF50008C71EDE8E0506DC94@MAIL_EXCHANGE обсуждение исходный текст |
| Ответ на | List sequence assigned to primary key ("Brian Johnson" <bjohnson@jecinc.on.ca>) |
| Список | pgsql-novice |
Brian Johnson wrote:
> I added a few records to a table and assigned numbers to the id field
> - now when I try to add records properly, it says that it can't
> accept duplicate values on the primary field (id)
>
> Although there were only a few records and I could just redo them, I
> wonder if there is another method (for future reference)
>
> So here are my two questions
>
> 1. How can you list (find out) the sequence name assigned to a
> primary key?
>
The sequence name for a serial field is:
tablename_fieldname_seq
eg:
CREATE TABLE tst (x SERIAL);
would create a sequence called:
tst_x_seq
> 2. How can you change that sequence value?
>
SELECT setval('seq_name',seq_value)
eg:
SELECT setval('tablename_fieldname_seq',MAX(field_name) FROM tablename;
To resync a sequence with a field.
hth,
- Stuart
В списке pgsql-novice по дате отправления: