nextval syntax

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

nextval syntax

От:
Justin Georgeson <jgeorgeson@unboundtech.com>
Дата:
Is there a way to have an application use "select sequence_name.nextval
..." in postgres? I want to keep the application working on oracle, but
want to use postgres for development/staging.

-- 
Justin Georgeson
UnBound Technologies, Inc.
http://www.unboundtech.com
Main   713.329.9330
Fax    713.460.4051
Mobile 512.789.1962

5295 Hollister Road
Houston, TX 77040
Real Applications using Real Wireless Intelligence(tm)

Re: nextval syntax

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Justin Georgeson  writes:
> Is there a way to have an application use "select sequence_name.nextval
> ..." in postgres? I want to keep the application working on oracle, but
> want to use postgres for development/staging.

How bad do you want it?  If you can tolerate making an interface
function for each sequence, you could do this:

regression=# create sequence seq;
CREATE SEQUENCE
regression=# select seq.nextval;
ERROR:  No such attribute seq.nextval
regression=# create function nextval(seq) returns int8 as 
regression-# 'select nextval(''seq'')' language sql;
CREATE FUNCTION
regression=# select seq.nextval;
 nextval 
---------
       1
(1 row)

regression=# select seq.nextval;
 nextval 
---------
       2
(1 row)


(This works in 7.3, not sure about older releases.)  Beware though
of using this in more complex selects, as the parser is likely to
think you mean a join of the sequence to the other tables...

			regards, tom lane

FAQ