Re: Implementing JDBC3 methods (Was: JDBC and fetching - Mailing list pgsql-jdbc

From Ross J. Reedstrom
Subject Re: Implementing JDBC3 methods (Was: JDBC and fetching
Date
Msg-id 20020919145711.GE17402@rice.edu
Whole thread Raw
In response to Re: Implementing JDBC3 methods (Was: JDBC and fetching  (Dave Cramer <Dave@micro-automation.net>)
Responses Re: Implementing JDBC3 methods (Was: JDBC and fetching  (Dave Cramer <Dave@micro-automation.net>)
List 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@rice.edu
Executive Director                                  phone: 713-348-6166
Gulf Coast Consortium for Bioinformatics              fax: 713-348-6182
Rice University MS-39
Houston, TX 77005

pgsql-jdbc by date:

Previous
From: João Paulo Ribeiro
Date:
Subject: Re: multiple users accessing database
Next
From: Dave Cramer
Date:
Subject: Re: Implementing JDBC3 methods (Was: JDBC and fetching