Re: SERIAL type fields

Jean-Luc Lachance <jllachan@nsd.ca>

From: Jean-Luc Lachance <jllachan@nsd.ca>
To: Andrew Ayers <aayers@eldocomp.com>
Cc: pgsql-general@postgresql.org
Date: 2003-04-24T19:59:34Z
Lists: pgsql-general
You should look up ALTER SEQUENCE

Andrew Ayers wrote:
> 
> All,
> 
> I have been doing a conversion of an Access 97 database to PostgreSQL -
> so far things have been going relatively smoothly. However, I am now
> running into a minor issue - one could almost say it is an asthetic
> issue more than anything.
> 
> In the conversion of my Access tables, to a number of them I had to add
> a unique key field. I decided to use a SERIAL type for these fields,
> which set up a "sequence" table (table_field_seq) for each table that
> uses one.
> 
> I am now in a process of doing a multiple conversion of data to these
> new tables, where I clear out the table then reload it with new data.
> 
> What I came across was that I wanted to reset the sequence number so
> that when the new records were added, they would start at number "1" and
> increase from there.
> 
> When you create the table from new, it does this - but after that, the
> sequence table says that the minimum value for the sequence is "1" - and
> not zero - so that when you add records to the table the sequence is
> used on, the first record has a value of "2" in that field when it is added.
> 
> I tried to reset the minimum value to "0" - but it wouldn't let me. Does
> anyone know of how you do this, without having to DROP the table and
> sequence, and re-creating them? Is there some kind of ALTER TABLE
> command, or possibly something the database setup, that would allow me
> to alter this behavior?
> 
> Thank you for any answers you can provide...
> 
> Andrew L. Ayers
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://archives.postgresql.org