Thread: currval and nextval in 7.3.4

currval and nextval in 7.3.4

From
Keith Marr
Date:
Hi,

I recently installed 7.3.4 (complete install from scratch) and both 'select
nextval('my_seq') from my_table' and 'select currval('my_seq') from my_table'
return a number of rows equal to the number of rows in the table.

The sequence was created with a SERIAL type if that helps.
 In 'psql' the results look like this.

my_db=# select nextval('my_seq') from my_table;
 nextval
---------
       6
       7
       8
       9
(4 rows)

my_db=# select currval('my_seq') from my_table;
 currval
---------
       9
       9
       9
       9
(4 rows)

I get the same results using the JDBC driver so it's not a psql problem.

Any thoughts out there?

Re: currval and nextval in 7.3.4

From
Stephan Szabo
Date:
On Thu, 23 Oct 2003, Keith Marr wrote:

> Hi,
>
> I recently installed 7.3.4 (complete install from scratch) and both 'select
> nextval('my_seq') from my_table' and 'select currval('my_seq') from my_table'
> return a number of rows equal to the number of rows in the table.
>
> The sequence was created with a SERIAL type if that helps.
>  In 'psql' the results look like this.
>
> my_db=# select nextval('my_seq') from my_table;
>  nextval
> ---------
>        6
>        7
>        8
>        9
> (4 rows)

This is what you asked for, for each row of my_table, call
nextval('my_seq') and return its value as an output row.
I'd guess that maybe you just want select nextval('myseq');
but I'm not sure.

Re: currval and nextval in 7.3.4

From
j6m@adm.estp.fr
Date:
Hello,

Quoting Keith Marr <marrk@comcast.net>:

> Hi,
>
> I recently installed 7.3.4 (complete install from scratch) and both 'select
>
> nextval('my_seq') from my_table' and 'select currval('my_seq') from my_table'
>
> return a number of rows equal to the number of rows in the table.
>
> The sequence was created with a SERIAL type if that helps.
>  In 'psql' the results look like this.
>

I think "select nextval('my_seq');" is what you want to do.

> my_db=# select nextval('my_seq') from my_table;
>  nextval
> ---------
>        6
>        7
>        8
>        9
> (4 rows)
>

Idem with select currval('my_seq');

> my_db=# select currval('my_seq') from my_table;
>  currval
> ---------
>        9
>        9
>        9
>        9
> (4 rows)
>
> I get the same results using the JDBC driver so it's not a psql problem.
>
> Any thoughts out there?
>
>

It is not a bug (or undocumented feature as some software vendor would say).
Your queries are syntaxically correct SQL requests, but they are not what you
really want.

(If you try "select now() from my_table;", it will also return 4 rows.)

Regards
J6M