Skip site navigation (1) Skip section navigation (2)

Re: Can't setval() a sequence to return the first value

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Hannu Krosing <hannu(at)2ndquadrant(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Can't setval() a sequence to return the first value
Date: 2013-01-03 11:23:19
Message-ID: CAFj8pRCpK3=6om+FUw=qQXr45Jfyisj8AO_4B-5RACrxCp6BqQ@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Hello

postgres=# select setval('xx', 1, false);
 setval
--------
      1
(1 row)

postgres=# select nextval('xx');
 nextval
---------
       1
(1 row)


Regards

Pavel

2013/1/3 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> Hi hackers.
>
> Is it by design that you can't setval(seq, value) a sequence to a value
> which returns the first value:
>
> See the sample below for better explanation:
>
> hannu=# create sequence s;
> CREATE SEQUENCE
> hannu=# select nextval('s');
>  nextval
> ---------
>        1
> (1 row)
> hannu=# select setval('s',1);
>  setval
> --------
>       1
> (1 row)
> hannu=# select nextval('s');
>  nextval
> ---------
>        2
> (1 row)
> hannu=# select setval('s',0);
> ERROR:  setval: value 0 is out of bounds for sequence "s"
> (1..9223372036854775807)
>
> Should it not be possible to set sequence to one below the start value so
> that you can completely reset it ?
>
> --------------------
> Hannu
>
>
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers


In response to

pgsql-hackers by date

Next:From: Hannu KrosingDate: 2013-01-03 11:34:23
Subject: Re: Re: Proposal: Store "timestamptz" of database creation on "pg_database"
Previous:From: Hannu KrosingDate: 2013-01-03 11:19:06
Subject: Can't setval() a sequence to return the first value

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group