Monday, 9 September 2013

How to use RETURNING clause in PostgreSQL?

How to use RETURNING clause in PostgreSQL?

I'm using PostgreSQL 8.2 (it should be the minimum version supporting
RETURNING), precisely 8.2.19 on GNU/Linux. I tried to use returning clause
on automatically inserted column that is also constrained as primary key.
The insertion of new row is correctly completed but the returned result is
empty (verified with query executer in pgAdmin). I tried implicit
insertion and also specifying DEFAULT for primary key column.
The column I tried to return is defined as
al_id integer NOT NULL DEFAULT
nextval(('"allarmi_al_id_seq"'::text)::regclass)
and the insertion query is like
INSERT INTO alarms (al_id, al_descr)
VALUES (DEFAULT, 'description')
RETURNING al_id;
allarmi_al_id_seq is obviously (?) a sequence and is defined as
CREATE SEQUENCE allarmi_al_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 34564230
CACHE 1;
What's wrong?

No comments:

Post a Comment