Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.databases.postgresql Subject: Re: Column Order Date: Fri, 04 Nov 2011 17:39:23 +0100 Lines: 28 Message-ID: <9hiipsF25kU1@mid.individual.net> References: <9hi005F3v8U1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 36kwIkiVEMthglQ0lNDRFAiBAmBh65tRnODzPvdi/zvZf/8iQ= Cancel-Lock: sha1:8Epib96S8WbMn/DjG0nAp6Bxd28= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 In-Reply-To: <9hi005F3v8U1@mid.individual.net> Xref: x330-a1.tempe.blueboxinc.net comp.databases.postgresql:274 On 11/04/2011 12:18 PM, Michael Hufschmidt wrote: > When I do a "SELECT * FROM myTable WHERE ..." using psql I want to have > the columns displayed in a meaningful order by default. I want to avoid > a "SELECT firstname, lastname, ...". Is it > possible to modify the order of columns with an > ALTER TABLE myTable ALTER COLUMN lastname > > Same holds for adding a new column, how can I > ALTER TABLE myTable ADD COLUMN title VARCHAR(255) > > This is possible in mySQL, not in PostgreSQL? > > Any ideas are welcome - Michael IMHO it is generally a bad idea to rely on column order because that may change etc. It's usually best to explicitly select columns in the order that you desire. You could define a view with the proper order on the table but you'll have to update that view definition every time your table has a new column. Bottom line: do not use "SELECT *" other than for briefly checking column contents. In any sort of application I would always name only those columns explicit which I need for the query. That may also save you a lot of network bandwidth between client and database server. Kind regards robert