4 ms·
What is the order of rows returned by insert ... returning? Going over docs it doesnt seem to be mentioned. This would be nice to retrieve auto generated prima
by orangepanda 6y ago
What is the order of rows returned by insert ... returning? Going over docs it doesnt seem to be mentioned.
This would be nice to retrieve auto generated primary keys when doing bulk inserts. Can this be done deterministically?
- murkt 6y agoI would be very surprised to learn that RETURNING order is different from the order of rows in INSERT statement. Some ORMs (at least SQLAlchemy) do that already, they can fill primary keys in your objects during single inserts, and in dicts during bulk insert.
- grzm 6y agoDon’t rely on the order: its implementation dependent. Results are sets of rows; unordered.
- murkt 6y agoWhat do you mean by “it’s implementation dependent”? RETURNING is a Postgres-specific clause, so of course its order is implementation dependent. There is only one Postgres, as far as I know.
- tpxl 6y agoThere are many versions of one Postgres :) If it's not defined in the docs/spec, it may change in the future (without notice).