pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sabin Coanda <sabin.coanda@deuromedia.ro>
To: pgsql-sql@postgresql.org
Subject: Re: system table storing sequence attributes
Date: Tue, 22 May 2007 16:12:06 +0300
Message-ID: <f2uq6o$112t$1@news.hub.org> (raw)
References: <f2u4jn$a03$1@news.hub.org>
	<pan.2007.05.22.07.43.23.678145@gmail.com>
	<f2unc1$kdo$1@news.hub.org>
	<pan.2007.05.22.12.41.38.862364@gmail.com>


""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 





view thread (9+ messages)  latest in thread

Message-ID: <f2uq6o$112t$1@news.hub.org>
Permalink:  ../f2uq6o$112t$1@news.hub.org/
Also on:    postgresql.org/message-id/f2uq6o$112t$1@news.hub.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sabin.coanda@deuromedia.ro
  Subject: Re: system table storing sequence attributes
  In-Reply-To: <f2uq6o$112t$1@news.hub.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox