Re: nextval syntax - Mailing list pgsql-ports

From Tom Lane
Subject Re: nextval syntax
Date
Msg-id 24424.1048881311@sss.pgh.pa.us
Whole thread Raw
In response to nextval syntax  (Justin Georgeson <jgeorgeson@unboundtech.com>)
List pgsql-ports
Justin Georgeson <jgeorgeson@unboundtech.com> 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


pgsql-ports by date:

Previous
From: Justin Georgeson
Date:
Subject: nextval syntax
Next
From: Brandon McMurray
Date:
Subject: Compile of pgsql v7.1.3 fails on Red Hat 8.0