[postgis-users] Identifying field names in select out of order

Brent Wood pcreso at pcreso.com
Tue Feb 21 10:23:02 PST 2006



> 
> This is PostgreSQL specific question. I'm iterating through my selection
> and need to get the field name of my data[$i] where
> $data=pg_fetch_row($result, $i). I've tried pg_fieldname($result, $i),
> but the problem is that the field names in the select statement are not
> in the same order as the db, so pg_fieldname(result, $i) is not the
> filed from which data[$i] is drawn from.  Is there another way of
> determining which field data[$i] comes from regardless of the field
> order?  Thank you.

AFAIK, all "normal" functions assume that the attribute order is the same as
that in the table. If you specify a different order in a query, you'll need to
refer back to the query statement to determine what attribute a given output
field represents.  

I guess you could create an array when you run the query to store the attr
names in, & then refer to this when needed?

Brent Wood



More information about the postgis-users mailing list