Re: I have some questions...

From: Michal Taborsky <michal(at)taborsky(dot)cz>
To: Prabu Subroto <prabu_subroto(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: I have some questions...
Date: 2004-08-02 13:50:25
Message-ID: 410E46A1.9090408@taborsky.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Prabu Subroto wrote:
> I still have problem with a new column into the
> current table (salesreport table). Because I can not
> find in the documentation of postgres how to define a
> new column into a current table "AFTER A CERTAIN
> COLUMN".
> on MySQL, I can do easily like this :
> "
> alter table salesreport add column emoicon(....) after
> report;
> "
> How can I do this on postgres?

You can't AFAIK. And you don't want to, either. I guess I know why you
ask about this--you are using "SELECT * FROM table" and then are
accessing "the fourth column". This, however, is bad practice and you
are asking for trouble. Don't count on the database engine to return
columns in any particular order, because the order is not guaranteed
(same as is not guaranteed the order of rows, if you don't specify an
ORDER BY clause.)

You should always specify column names, if your application is accessing
columns according to their position in returned result. You have two
possibilities:

a) Specify exact column names and order in query:
SELECT column1, column2 FROM table
Then it is safe to print $row[0] and $row[1] (in PHP array form, just an
example)

b) Use named columns interface:
SELECT * FROM table
Then in application level use $row['column1'] (again PHP example) -- I
think most languages provide this functionality

--
Michal Taborsky
http://www.taborsky.cz

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-08-02 14:05:23 Re: How to use as Functional Index to be used as Primary KEY
Previous Message Prabu Subroto 2004-08-02 13:26:35 Re: I have some questions...