Re: GETTING INFO FROM SEQUENCE OBJECTS

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: GETTING INFO FROM SEQUENCE OBJECTS
Date: 2009-11-03 06:22:40
Message-ID: 20091103062240.GA9363@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

In response to JORGE MALDONADO :
> How do I use the functions to get data from sequence objects?
> For example, I need to know what is the value of a serial field after inserting
> a new record; the one assigned to the record just inserted.
>  
> I have tried the psql interfase with the following:
> select currval('restaurant.ordenes_clave_seq');
> but I get a message telling me that "currval of sequence "ordenes_clave_seq" is
> not yet defined in this session.

You have to use nextval() first, without nextval() the current value of
the sequence are undefined in this session.

In other words: first insert your new row into the table, after that
call currval().

Regards, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99

In response to

Responses

  • corrupt db at 2009-11-03 18:00:32 from Lars Gustafsson

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Lush 2009-11-03 17:04:49 Determining database status
Previous Message Brian Modra 2009-11-03 06:15:36 Re: GETTING INFO FROM SEQUENCE OBJECTS