[Mapbender-dev] Column names

Karim Malhas karim at malhas.de
Wed Apr 28 11:55:44 EDT 2010


Hi Michael,

Thank you for your response.
I thought about this more and I drifted off a little, so feel free to 
ignore any offtopicness.

> 
> not sure, if there is deeper reasoning behind it (i guess it may be ),
> but I try to follow this approach because otherwise you always have to
> be careful to not include a column of the name "wms_id" more then
> once. I am personally not in favour of aliasing column names when not
> really necessary, eg. when you need to output the column name as a
> header... otherwise it just shows that the column naming was
> ambiguous.

It seems to me, that it's usually a good Idea to avoid 
statements like

  SELECT * FROM table,

because when dealing with data, it's good to be precise.
And it's actually why I noticed, because I was typing all these
'table.table_column' col_names into my SELECT clauses and thought that things might
be easier if they involved an alias every now and then instead of 
specifying the table twice, all the time.

Within the query that's not a problem, because 

  SELECT a.*,b.* FROM a JOIN a.id on b.id;

works well.
The columnname conflict only starts on the client side, where a
fetch_assoc returns an array like...

wait, that can't be right ?

given these databases

a:
name|age
--------
foo |12

b:
name | age
----------
bar  | 13


and this statement:

"SELECT a.*,b.* FROM a,b;"

pg_fetch_assoc() returns this array:

  array("name"=>"bar","age"=>"13")

Silently ignoring the 'name' and 'age' columns of the a table.

..."interesting"

I guess specifying the tablename as part of the columnname is a solution
to that problem.

Regards,
Karim


More information about the Mapbender_dev mailing list