From: | "Henshall, Stuart - Design & Print" <SHenshall(at)westcountry-design-print(dot)co(dot)uk> |
---|---|
To: | 'Brian Johnson' <bjohnson(at)jecinc(dot)on(dot)ca>, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: List sequence assigned to primary key |
Date: | 2002-11-05 14:14:20 |
Message-ID: | E2870D8CE1CCD311BAF50008C71EDE8E0506DC94@MAIL_EXCHANGE |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Mark Nelson | 2002-11-06 01:00:16 | Resource id #3? |
Previous Message | Ciprian Popovici | 2002-11-05 09:34:52 | OT: displaying sender's email on archives.postgresql.org |