Clustered table order is not preserved on insert - Mailing list pgsql-general

From Andrus
Subject Clustered table order is not preserved on insert
Date
Msg-id e2ofnp$m5b$1@news.hub.org
Whole thread Raw
Responses Re: Clustered table order is not preserved on insert  (Douglas McNaught <doug@mcnaught.org>)
Re: Clustered table order is not preserved on insert  (Richard Huxton <dev@archonet.com>)
List pgsql-general
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.




pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: pg_dump -t <> pg_restore -t
Next
From: Douglas McNaught
Date:
Subject: Re: Clustered table order is not preserved on insert