Обсуждение: Selecting Current value from a sequence

Поиск
Список
Период
Сортировка

Selecting Current value from a sequence

От
Najm Hashmi
Дата:
Hi all,It is a very simple but I am not able to recall  how to do it.... I
just need to find out the  current value of a seq. It is very simple
select statement but I can't recall it... Help me please before I get
myself get fired -:).
Regards, Najm



Re: Selecting Current value from a sequence

От
Josh Berkus
Дата:
Najm
CURRVAL('sequence_name')
For this and other sequence and serial functions, please see the online
version of Bruce's book.
BTW, O'Reilly's "SQL in at Nutshell" also catalogs all PGSQL functions
from ver. 6.5.
                -Josh Berkus
-- 
______AGLIO DATABASE SOLUTIONS___________________________                                       Josh Berkus  Complete
informationtechnology      josh@agliodbs.com   and data management solutions       (415) 436-9166  for law firms, small
businesses      fax  436-0137   and non-profit organizations.       pager 338-4078                               San
Francisco


Re: Selecting Current value from a sequence

От
George Moga
Дата:
Najm Hashmi wrote:

> Hi all,
>  It is a very simple but I am not able to recall  how to do it.... I
> just need to find out the  current value of a seq. It is very simple
> select statement but I can't recall it... Help me please before I get
> myself get fired -:).
>

Try:

SELECT last_value FROM sequence_name;


> Regards, Najm

For me works (PostgreSQL 7.0.3, Mandrake Linux 7.2).

George Moga,   Data Systems Srl   Slobozia, ROMANIA




Re: Selecting Current value from a sequence

От
Bruce Momjian
Дата:
> Najm
> 
>     CURRVAL('sequence_name')
> 
>     For this and other sequence and serial functions, please see the online
> version of Bruce's book.
> 
>     BTW, O'Reilly's "SQL in at Nutshell" also catalogs all PGSQL functions
> from ver. 6.5.

It does, or only the standard SQL functions?  Do they have
PostgreSQL-specific stuff.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: Selecting Current value from a sequence

От
clayton cottingham
Дата:
Najm Hashmi wrote:
> 
> Hi all,
>  It is a very simple but I am not able to recall  how to do it.... I
> just need to find out the  current value of a seq. It is very simple
> select statement but I can't recall it... Help me please before I get
> myself get fired -:).
> Regards, Najm


select nextval('nameofseq');


Re: Selecting Current value from a sequence

От
Bruce Momjian
Дата:
See my book on sequences:
http://www.postgresql.org/docs/awbook.html

currval() is probably what you need.

> Hi all,
>  It is a very simple but I am not able to recall  how to do it.... I
> just need to find out the  current value of a seq. It is very simple
> select statement but I can't recall it... Help me please before I get
> myself get fired -:).
> Regards, Najm
> 
> 


--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: Selecting Current value from a sequence

От
Najm Hashmi
Дата:
Thank you all for  your help.
Najm



Re: Selecting Current value from a sequence

От
Josh Berkus
Дата:
Clayton,

> > Hi all,
> >  It is a very simple but I am not able to recall  how to do it.... I
> > just need to find out the  current value of a seq. It is very simple
> > select statement but I can't recall it... Help me please before I get
> > myself get fired -:).
> > Regards, Najm
> 
> select nextval('nameofseq');

Sorry, no.  You want SELECT CURRVAL('sequence_name').  NEXTVAL select
the NEXT value, and increments the sequence in the process.

-Josh Berkus

-- 
______AGLIO DATABASE SOLUTIONS___________________________                                       Josh Berkus  Complete
informationtechnology      josh@agliodbs.com   and data management solutions       (415) 436-9166  for law firms, small
businesses      fax  436-0137   and non-profit organizations.       pager 338-4078                               San
Francisco


Re: Selecting Current value from a sequence

От
Josh Berkus
Дата:
Bruce,

> >       BTW, O'Reilly's "SQL in at Nutshell" also catalogs all PGSQL functions
> > from ver. 6.5.
> 
> It does, or only the standard SQL functions?  Do they have
> PostgreSQL-specific stuff.

Both.  The book is set up to cover 1) the SQL99 standard, and 2)
Specific variants for SQL Server, MySQL, Oracle and PostgreSQL.

Unfortunately, the book was somewhat delayed in publication ( + 4 months
past list) so that it is a little out of date.  Pgsql 6.5 is covered
without any notation on what will change/be added in 7.x.  Still, since
I don't even *have* your book yet, it's better than nothing! :-)
                -Josh Berkus

-- 
______AGLIO DATABASE SOLUTIONS___________________________                                       Josh Berkus  Complete
informationtechnology      josh@agliodbs.com   and data management solutions       (415) 436-9166  for law firms, small
businesses      fax  436-0137   and non-profit organizations.       pager 338-4078                               San
Francisco