Re: I have some questions... - Mailing list pgsql-general

From Michal Taborsky
Subject Re: I have some questions...
Date
Msg-id 410E46A1.9090408@taborsky.cz
Whole thread Raw
In response to Re: I have some questions...  (Prabu Subroto <prabu_subroto@yahoo.com>)
List 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


pgsql-general by date:

Previous
From: Prabu Subroto
Date:
Subject: Re: I have some questions...
Next
From: Tom Lane
Date:
Subject: Re: How to use as Functional Index to be used as Primary KEY