Re: nextval syntax

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Justin Georgeson <jgeorgeson(at)unboundtech(dot)com>
Cc: pgsql-ports(at)postgresql(dot)org
Subject: Re: nextval syntax
Date: 2003-03-28 19:55:11
Message-ID: 24424.1048881311@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-ports

Justin Georgeson <jgeorgeson(at)unboundtech(dot)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

In response to

Browse pgsql-ports by date

  From Date Subject
Next Message rashmi 2003-03-29 13:40:21 an error regarding pg_dump
Previous Message Justin Georgeson 2003-03-28 18:56:46 nextval syntax