Search Postgresql Archives

Clustered table order is not preserved on insert

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

 



I have table of reports

CREATE TABLE report (
ReportName CHAR(5) not null check (reportname<>''),
< a lot of other fields >,
id serial primary key
)

I want to duplicate report so that id order is preserved.

BEGIN;
CREATE temp TABLE tempreport AS
      SELECT * FROM report
      WHERE reportname='oldr'
      ORDER BY id;

ALTER TABLE tempreport DROP COLUMN id;
update tempreport set  reportname='newr';
insert into report SELECT * FROM tempreport;
DROP TABLE tempreport;
COMMIT;

SELECT *
FROM  report
WHERE reportname='newr'
ORDER BY id;

Observed:

order of some rows in newr is different than in oldr

Expected:

newr must have exactly the same order since
CREATE temp TABLE tempreport AS  .... ORDER BY id
creates clustered table.

Is this best method to preform this?
Why postgres 8.1.3 changes order ?
How to preserve order in newr without adding extra field to report table ?

Andrus.





[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