Re: change natural column order

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: Pierre-Frédéric Caillaud <lists(at)boutiquenumerique(dot)com>, "Greg Stark" <gsstark(at)mit(dot)edu>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: change natural column order
Date: 2004-11-30 23:03:37
Message-ID: D425483C2C5C9F49B5B7A41F894415470556C1@postal.corporate.connx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Using "SELECT * FROM <table_name>" from the PSQL prompt or any other interactive tool is perfectly fine.

Putting "SELECT * FROM <table_name>" into a compiled program using libpq or ESQL is a code defect. Period.

ALTER TABLE ADD COLUMN /* Most frequent defect maker for SELECT * */

ALTER TABLE DROP COLUMN /* If you didn't need the column, who cares */

ALTER TABLE RENAME COLUMN /* This will be a problem either way, but at least you will find out about it. It also shows why renaming columns is almost always a very, very bad idea after any release. */

ALTER TABLE SET WITHOUT OIDS {PG specific} /* One fewer column now, and all the column numbers are now 'off-by-one' */

DROP TABLE/CREATE TABLE /* New version may have the same name and the same number of columns, and they may even have the same data types but there is no guarantee that the meaning is the same. */

The list goes on and on.

It is a defect of equal magnitude to assume that columns are returned in any particular order unless specified in a column list (again, from a program and not interactively).

Another typical defect is to assume that columns come backed ordered by the primary key if the table is clustered on the primary key column. You can have a page split with many database systems and so there is no guarantee that data will be returned in order without an ORDER BY clause -- clustered or not.

Any of (ASSMUME NO COLUMN CHANGES/ASSUME COLUMN ORDER/ASSUME CLUSTERED KEY SORT ORDER) would cause me to fail code in a code review.

IMO-YMMV

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jim C. Nasby 2004-11-30 23:15:34 Re: Postgres Design
Previous Message Woodchuck Bill 2004-11-30 22:55:00 Re: [ANNOUNCE] USENET vs Mailing Lists Poll ...