[SQL] system table storing sequence attributes
Hi there, I'd like to read the global sequence attribute "currval", but not using currval function, because it is session dependent and requires a nextval function to be used before. Do you know where is stored this value in the system tables ? TIA, Sabin ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [SQL] system table storing sequence attributes
Dnia Tue, 22 May 2007 10:03:28 +0300, Sabin Coanda napisał(a): > Hi there, > > I'd like to read the global sequence attribute "currval", but not using > currval function, because it is session dependent and requires a nextval > function to be used before. > > Do you know where is stored this value in the system tables ? select last_value from sequence_name -- | And Do What You Will be the challenge | http://apcoln.linuxpl.org |So be it in love that harms none | http://biznes.linux.pl | For this is the only commandment. | http://www.juanperon.info `---* JID: [EMAIL PROTECTED] *---' http://www.naszedzieci.org ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [SQL] system table storing sequence attributes
... > select last_value from sequence_name Unfortunately there is the same problem. The documentation say: "It is an error to call lastval if nextval has not yet been called in the current session." and I don't want to call nextval before. Sabin ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster
Re: [SQL] system table storing sequence attributes
am Tue, dem 22.05.2007, um 15:23:44 +0300 mailte Sabin Coanda folgendes: > ... > > select last_value from sequence_name > > Unfortunately there is the same problem. The documentation say: "It is an > error to call lastval if nextval has not yet been called in the current > session." and I don't want to call nextval before. No, you can select last_value from a sequence. Welcome to psql 8.1.4, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit test=# select last_value from t2_seq; last_value 3 (1 row) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster
Re: [SQL] system table storing sequence attributes
Dnia Tue, 22 May 2007 15:23:44 +0300, Sabin Coanda napisał(a): > ... >> select last_value from sequence_name > > Unfortunately there is the same problem. The documentation say: "It is an > error to call lastval if nextval has not yet been called in the current > session." and I don't want to call nextval before. 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. -- | And Do What You Will be the challenge | http://apcoln.linuxpl.org |So be it in love that harms none | http://biznes.linux.pl | For this is the only commandment. | http://www.juanperon.info `---* JID: [EMAIL PROTECTED] *---' http://www.naszedzieci.org ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [SQL] system table storing sequence attributes
""Marcin Stêpnicki"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
...
>
> 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
---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
Re: [SQL] system table storing sequence attributes
am Tue, dem 22.05.2007, um 16:12:06 +0300 mailte Sabin Coanda folgendes:
> 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
Try 'select last_value from "tbFoo_ID_seq";' instead.
A. Kretschmer
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
---(end of broadcast)---
TIP 6: explain analyze is your friend
Re: [SQL] system table storing sequence attributes
""A. Kretschmer"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] ... > > Try 'select last_value from "tbFoo_ID_seq";' instead. > It works. Thanks a lot ! Sabin ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [SQL] system table storing sequence attributes
Sabin Coanda написа: > ""Marcin Stкpnicki"" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > ... >> 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. Why do you need to know that? I can't think of any reason. [...] -- Milen A. Radev ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings
