From: | "Ross J(dot) Reedstrom" <reedstrm(at)rice(dot)edu> |
---|---|
To: | "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Re: Implementing JDBC3 methods (Was: JDBC and fetching |
Date: | 2002-09-19 14:57:11 |
Message-ID: | 20020919145711.GE17402@rice.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
On Thu, Sep 19, 2002 at 05:25:01AM -0400, Dave Cramer wrote:
> That's the only way, and will have to do. One thing to realize is that
> once a sequence has been used, it can't be rolled back, so it is unique.
Not really - you can set it to any number at all, or even reset it,
so the first call to nextval() returns the inital value. I do this
all the time when loading data into a schema, to set the sequences for
serial columns so they don't cause errors, something like:
select setval('mytable_id_seq',max(id)) from mytable
Here's demonstrating resetting to 'virgin':
test=# create sequence testit;
CREATE
test=# select nextval('testit');
nextval
---------
1
(1 row)
test=# select nextval('testit');
nextval
---------
2
(1 row)
test=# select currval('testit');
currval
---------
2
(1 row)
test=# select setval('testit',1,'f');
setval
--------
1
(1 row)
test=# select nextval('testit');
nextval
---------
1
(1 row)
Ross
--
Ross Reedstrom, Ph.D. reedstrm(at)rice(dot)edu
Executive Director phone: 713-348-6166
Gulf Coast Consortium for Bioinformatics fax: 713-348-6182
Rice University MS-39
Houston, TX 77005
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2002-09-19 18:41:28 | Re: Implementing JDBC3 methods (Was: JDBC and fetching |
Previous Message | João Paulo Ribeiro | 2002-09-19 10:31:48 | Re: multiple users accessing database |