Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 78C479FB4D0 for ; Tue, 22 May 2007 10:12:04 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 44952-03-3 for ; Tue, 22 May 2007 10:11:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id EC8949FB442 for ; Tue, 22 May 2007 10:12:02 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 852DF30AF0; Tue, 22 May 2007 15:12:00 +0200 (MET DST) From: "Sabin Coanda" X-Newsgroups: pgsql.sql Subject: Re: system table storing sequence attributes Date: Tue, 22 May 2007 16:12:06 +0300 Organization: Hub.Org Networking Services Lines: 51 Message-ID: References: X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/155 X-Sequence-Number: 28435 ""Marcin Stêpnicki"" 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