Re: Question on doc for RETURNING clause - Mailing list pgsql-docs

From David G. Johnston
Subject Re: Question on doc for RETURNING clause
Date
Msg-id CAKFQuwZ0sJ1TJViLkmi7GVBTFF7Uzq3gFM+C5HCYrbYBkq++7Q@mail.gmail.com
Whole thread Raw
In response to Question on doc for RETURNING clause  ("Russell, John" <johrss@amazon.com>)
List pgsql-docs
On Thu, Jan 11, 2024 at 11:55 AM Russell, John <johrss@amazon.com> wrote:
```
postgres=> insert into generatedfields (x) values (0), (10), (100) order by 2 desc returning id, x;
ERROR:  ORDER BY position 2 is not in select list
LINE 1: ...eratedfields (x) values (0), (10), (100) order by 2 desc ret...
                                                             ^
```

Is the acceptance of ORDER BY documented anywhere?

VALUES, like SELECT, is an SQL Command in its own right.


That is what you are ordering, before attempting insertion.  Hence why it only sees one column.

 
I didn’t see that anywhere in the INSERT syntax. Does it have any practical effect if there’s no RETURNING clause, e.g. do the rows get physically inserted in the ORDER BY order, which could have implications for columns like SERIAL?

At present, the order of rows presented to the insert does in no way compel the insert command to act on the provided rows in order; even though in practice it will seem to do so.

David J.

pgsql-docs by date:

Previous
From: "Russell, John"
Date:
Subject: Question on doc for RETURNING clause
Next
From: Tom Lane
Date:
Subject: Re: Question on doc for RETURNING clause