Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>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.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux