Re: Implementing JDBC3 methods (Was: JDBC and fetching

From: Dave Cramer <Dave(at)micro-automation(dot)net>
To: "Ross J(dot) Reedstrom" <reedstrm(at)rice(dot)edu>
Cc: "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 18:41:28
Message-ID: 1032460936.26943.116.camel@inspiron.cramers
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Ross,

I realize that you can do this, but that is sort of going beyond what
most ppl will do. Also you can't insert a duplicate into a serial type.

But technically you are correct.

Dave
On Thu, 2002-09-19 at 10:57, Ross J. Reedstrom wrote:
> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Sean Gates 2002-09-19 18:56:05 Patch for 'updateNull' method null pointer exception
Previous Message Ross J. Reedstrom 2002-09-19 14:57:11 Re: Implementing JDBC3 methods (Was: JDBC and fetching