Re: Example of RETURNING clause to get auto-generated keys - Mailing list pgsql-general

From Tom Lane
Subject Re: Example of RETURNING clause to get auto-generated keys
Date
Msg-id 14826.1169704431@sss.pgh.pa.us
Whole thread Raw
In response to Re: Example of RETURNING clause to get auto-generated keys  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-general
Alvaro Herrera <alvherre@commandprompt.com> writes:
> Ken Johanson wrote:
>> Just to be sure, will the RETURNING clause work with custom sequences
>> (say, non numeric or increment by two) or other types of key
>> generators?... And how will triggers interfere with it (if at all)?

> As far as I know, RETURNING will give you exactly the values that are
> put into the table.

RETURNING evaluates the given expression-list over the values that were
actually stored.  There's no way for a datatype or BEFORE trigger to
"fool" it.  The only possibly interesting case is if you had an AFTER
trigger that proceeded to modify the stored row by issuing an UPDATE
... but that would be a pretty silly/inefficient way to do things,
and even then I think that RETURNING is telling the truth as of the time
that the tuple insert/update happened.  It can't be supposed to be
prescient about subsequent changes.

            regards, tom lane

pgsql-general by date:

Previous
From: "Merlin Moncure"
Date:
Subject: Re: indexing primary and foreign keys w/lookup table
Next
From: Bruno Wolff III
Date:
Subject: Re: indexing primary and foreign keys w/lookup table