Re: Semantics around INSERT INTO with SELECT and ORDER BY.

2018-06-12 Thread Steve Krenzel
Thank you all! Your answers cleared this up for me. Tom, in particular, that reference commit removed any ambiguity for me. Thank you. It's much appreciated. On Tue, Jun 12, 2018 at 7:27 AM Tom Lane wrote: > "David G. Johnston" writes: > > On Tuesday, June 12, 2018, Steve Krenzel wrote: > >>

Re: Semantics around INSERT INTO with SELECT and ORDER BY.

2018-06-12 Thread Tom Lane
"David G. Johnston" writes: > On Tuesday, June 12, 2018, Steve Krenzel wrote: >> This is relevant for tables that have a column with a SERIAL type, I need >> to guarantee that the relative ordering remains the same as the ordering of >> the selected result set. > The logical insertion order, and

Re: Semantics around INSERT INTO with SELECT and ORDER BY.

2018-06-12 Thread Adrian Klaver
On 06/12/2018 01:39 AM, Steve Krenzel wrote: This is relevant for tables that have a column with a SERIAL type, I need to guarantee that the relative ordering remains the same as the ordering of the selected result set. More concretely, given:     > CREATE TABLE foo (id SERIAL, val TEXT);  

Re: Semantics around INSERT INTO with SELECT and ORDER BY.

2018-06-12 Thread David G. Johnston
On Tuesday, June 12, 2018, Steve Krenzel wrote: > This is relevant for tables that have a column with a SERIAL type, I need > to guarantee that the relative ordering remains the same as the ordering of > the selected result set. > The logical insertion order, and thus the sequence values, will b

Re: Semantics around INSERT INTO with SELECT and ORDER BY.

2018-06-12 Thread Ravi Krishna
>Or to put it another way, I want to select values from one table ordered by >complex criteria and insert them into another table. I want to be able to >retrieve the rows from the target table in the same order they were inserted, >but I don't care about the specific ordering criteria. I only care

Re: Semantics around INSERT INTO with SELECT and ORDER BY.

2018-06-12 Thread Steve Krenzel
This is relevant for tables that have a column with a SERIAL type, I need to guarantee that the relative ordering remains the same as the ordering of the selected result set. More concretely, given: > CREATE TABLE foo (id SERIAL, val TEXT); > CREATE TABLE bar (id SERIAL, val TEXT); >

Re: Semantics around INSERT INTO with SELECT and ORDER BY.

2018-06-12 Thread Ravi Krishna
Why is it even important? Once you use ORDER BY clause, you are guaranteed to get the rows in the order. Why do you need how it was inserted in the first place.

Semantics around INSERT INTO with SELECT and ORDER BY.

2018-06-12 Thread Steve Krenzel
If I insert using the results of a select statement, are the inserts guaranteed to happen in the order of the rows returned from the select? That is, are these two equivalent: INSERT INTO SELECT FROM ORDER BY DESC; And: FOR row IN SELECT FROM ORDER BY DESC LOOP INSERT INT