Re: system table storing sequence attributes - Mailing list pgsql-sql

From Sabin Coanda
Subject Re: system table storing sequence attributes
Date
Msg-id f2uq6o$112t$1@news.hub.org
Whole thread Raw
In response to system table storing sequence attributes  ("Sabin Coanda" <sabin.coanda@deuromedia.ro>)
Responses Re: system table storing sequence attributes  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Re: system table storing sequence attributes  ("Milen A. Radev" <milen@radev.net>)
List pgsql-sql
""Marcin St�pnicki"" <mstepnicki@gmail.com> wrote in message 
news:pan.2007.05.22.12.41.38.862364@gmail.com...
...
>
> I think that you either misunderstood this statement or try to break your
> application in a nasty way ;). Please tell us more about your problem
> and/or what do you want to achive, because sequences behave this way for a
> reason (concurrency issues). Perhaps there is another solution.

I have a table with a serial primary key aoto generated by a sequence. I 
add/remove records. At a moment I'd like to know what is the current value 
of the sequence. I don't wish to know this in the same session where I 
add/remove records.

My Postgresql version is "PostgreSQL 8.2.3 on i686-pc-mingw32, compiled by 
GCC gcc.exe (GCC) 3.4.2 (mingw-special)", on Windows XP OS, and I use 
pgAdmin to open sessions on my database.

With this environment, try the following scenario:

Make a demo table:
CREATE TABLE "tbFoo"
( "ID" integer NOT NULL DEFAULT nextval('"tbFoo_ID_seq"'::regclass)
)

At the beginning, no record are inserted in the table. I call:
SELECT currval( pg_get_serial_sequence('"tbFoo"','ID') );

This rise the following error: ERROR: currval of sequence "tbFoo_ID_seq" is 
not yet defined in this session
SQL state: 55000

Then I add a record there:
INSERT INTO "tbFoo" DEFAULT VALUES;

I call SELECT currval( pg_get_serial_sequence('"tbFoo"','ID') ), and I get 
1. That's ok because I just use indirectly a nextval to that sequence in the 
insert process, on this session.

I close the session, and I open another one.

I call SELECT currval( pg_get_serial_sequence('"tbFoo"','ID') ), and I get 
the error again:
ERROR: currval of sequence "tbFoo_ID_seq" is not yet defined in this session
SQL state: 55000

Sabin 




pgsql-sql by date:

Previous
From: Marcin Stępnicki
Date:
Subject: Re: system table storing sequence attributes
Next
From: "A. Kretschmer"
Date:
Subject: Re: system table storing sequence attributes