Re: system table storing sequence attributes

From: "Sabin Coanda" <sabin(dot)coanda(at)deuromedia(dot)ro>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: system table storing sequence attributes
Date: 2007-05-22 13:12:06
Message-ID: f2uq6o$112t$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


""Marcin Stpnicki"" <mstepnicki(at)gmail(dot)com> wrote in message
news:pan(dot)2007(dot)05(dot)22(dot)12(dot)41(dot)38(dot)862364(at)gmail(dot)com(dot)(dot)(dot)
...
>
> 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message A. Kretschmer 2007-05-22 13:22:43 Re: system table storing sequence attributes
Previous Message Marcin Stępnicki 2007-05-22 12:41:38 Re: system table storing sequence attributes