Search Postgresql Archives

Re: Reordering columns in a table

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

 



I would certainly never have any of my normal application code depend on the ordering of columns. My desire for column ordering is strictly for administration purposes, keeping the visual clarity of the datamodel, and ensuring that the visual datamodel is consistent with what is actually in the database.

When one initially designs a database, thought goes into the ordering of columns (at least, I hope it does). In a large table it makes sense to group like columns. Using my line of work as an example, if you are storing the first and last names of the insured and claimant in a claim record, one would not consciously define the table as:

insured_firstname varchar(32),
claimant_lastname varchar(32),
insured_lastname varchar(32),
claimant_firstname varchra(32)

However, in the real world, columns are often added willy-nilly as they are needed, and it is not immediately obvious which, if any, of the columns will be related. Later, solely for visual clarity, it is desirable to have the ability to reorder the columns in the database. I wouldn't depend on this ordering for a "select *" query. But I *would* like the columns to appear in this order whenever any Postgres administration tool asked for the column list of a table, that way it appears the way I like in PgAdminIII, the \d command of psql, etc. etc.

John


Andreas Kretschmer wrote:

Not really sarcastic. You can't expect the order of values in a table,
and you can't expect the order of columns in a table.

If you do a 'select * from ...', and the table-structure is changed,
then you get problems. If you do a 'select col1, col2, col2, ... coln
...'), no problems.

A (german) article about this (with mysql):
http://php-faq.de/q/q-sql-select.html


HTH, Andreas



[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