Selecting Current value from a sequence

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

Selecting Current value from a sequence

От:
Najm Hashmi <najm@mondo-live.com>
Дата:
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 <josh@agliodbs.com>
Дата:
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 information technology      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 <george@cicnet.ro>
Дата:
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 <pgman@candle.pha.pa.us>
Дата:
> 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, Pennsylvania 19026

Re: Selecting Current value from a sequence

От:
clayton cottingham <drfrog@smartt.com>
Дата:
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 <pgman@candle.pha.pa.us>
Дата:
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, Pennsylvania 19026

Re: Selecting Current value from a sequence

От:
Najm Hashmi <najm@mondo-live.com>
Дата:
Thank you all for  your help.
Najm


Re: Selecting Current value from a sequence

От:
Josh Berkus <josh@agliodbs.com>
Дата:
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 information technology      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 <josh@agliodbs.com>
Дата:
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 information technology      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

FAQ