Thread: Serial Type

Serial Type

From
"Christian Marschalek"
Date:
The serial data type automaticaly takes the next higher value, but what
if there's a drop and I want to assing 3 even if there are 20 records
and the next higher number would be 21 not 3?

Tia Chris


Re: Serial Type

From
Justin Clift
Date:
Hi Chris,

If you do an INSERT straight into the table, AND also make sure you give
it the value you want in the serial column, it will accept it and not
increment the serial column's counter.

There are also a few function which are useful with the serial type :

currval()
setval()
nextval()

See http://odbc.postgresql.org/docs/index.php?sql-createsequence.html
for more info.

Regards and best wishes,

Justin Clift

Christian Marschalek wrote:
>
> The serial data type automaticaly takes the next higher value, but what
> if there's a drop and I want to assing 3 even if there are 20 records
> and the next higher number would be 21 not 3?
>
> Tia Chris
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl

--
"My grandfather once told me that there are two kinds of people: those
who work and those who take the credit. He told me to try to be in the
first group; there was less competition there."
     - Indira Gandhi

Re: Serial Type

From
Peter Eisentraut
Date:
Christian Marschalek writes:

> The serial data type automaticaly takes the next higher value, but what
> if there's a drop and I want to assing 3 even if there are 20 records
> and the next higher number would be 21 not 3?

Then you can't use the serial type.  Coding hole-filling serial numbers
can be quite tricky and slow.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter