Categories
Database PostgreSQL

PostgreSQL Doesn’t Support ‘FROM dual’

In Oracle I got used to getting the next value (nextval) in a sequence by doing something like this:

SELECT some_sequence.nextval new_seq_value
FROM dual

As a note to myself (and anyone else Googling for this) PostgreSQL does NOT support the ‘FROM dual’ syntax. It does however make the ‘FROM’ portion of a query like this optional, so getting the next value (nextval) of a sequence you would do something like this:

SELECT nextval(some_sequence) AS new_seq_value

This was one of those things that I had known before but lately I’ve been up to my elbows in Oracle and I drew a blank when I switched back to PostgreSQL for a bit of work.

If you are porting from Oracle to PostgreSQL there is a PDF on the net by Paulo Merson dated February 2002 that has some useful tips. For a quick look try the Google Cache’s HTML version of Paulo’s PDF.

Leave a Reply

Your email address will not be published. Required fields are marked *