Re: Semantics around INSERT INTO with SELECT and ORDER BY. - Mailing list pgsql-general

From Ravi Krishna
Subject Re: Semantics around INSERT INTO with SELECT and ORDER BY.
Date
Msg-id CACER=P2AL6G5ZC4HQFhXBAAYXQ5-tmEdOcbcyUbUwzece9vjsA@mail.gmail.com
Whole thread Raw
In response to Re: Semantics around INSERT INTO with SELECT and ORDER BY.  (Steve Krenzel <sgk284@gmail.com>)
List pgsql-general
>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 about the order they were inserted.

As I understand, your business requirement is to retrieve the rows from the target 
table the same way they were inserted.  The one and only way to achieve it is
to use the same ORDER by clause to SELECT from target, what it was used
to insert into target. In your case, the insert is
 INSERT INTO bar (val) SELECT val FROM foo ORDER BY id DESC;
So the SELECT should also be ORDER BY ID desc

Just don't care on how it inserts and stores row internally.

pgsql-general by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Bad performance with cascaded deletes
Next
From: Bo Peng
Date:
Subject: Re: Add to watchdog cluster request is rejected by node