Re: Implementing JDBC3 methods (Was: JDBC and fetching

Поиск
Список
Период
Сортировка
От Ross J. Reedstrom
Тема Re: Implementing JDBC3 methods (Was: JDBC and fetching
Дата
Msg-id 20020919145711.GE17402@rice.edu
обсуждение исходный текст
Ответ на Re: Implementing JDBC3 methods (Was: JDBC and fetching  (Dave Cramer <Dave@micro-automation.net>)
Ответы Re: Implementing JDBC3 methods (Was: JDBC and fetching
Список 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 по дате отправления:

Предыдущее
От: João Paulo Ribeiro
Дата:
Сообщение: Re: multiple users accessing database
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: Implementing JDBC3 methods (Was: JDBC and fetching