If you have a query that selects fields of the same name from more than one 
table, BEWARE!!!

Postgresql automatically adds a trailing underscore and a number to each 
field name on the second or subsequent occurrence in order to return a 
unique name for each field. PHP apparently removes these, creating a 
duplicate field name. I would expect the same to occur with table field 
names that actually contain an underscore (don't know whether Postgres 
allows underscores in field names).

The result will be of course that when you use any Postgres function that 
retrieves a named field, there may be two fields that have the same name as 
far as PHP is concerned and you won't be able to identify the field by its 
underscored Postgres name.

If you use pg_fetch_array then unpredictable things will occur as 
(presumably) the data from the first occurrence of the field name gets 
overwritten by the data of the second occurrence as fields are retrieved 
from the row. I found this occurred when I wrote my own fetch code as below:

        function pgFetchArray($rsid,$rownum)
        {
                $fldcount = pg_numfields($rsid);
                for ($fld=0;$fld<$fldcount;$fld++)
                {
                        $fldname = pg_fieldname($rsid,$fld);
                        $flddata = pg_result($rsid,$rownum,$fld);
                        echo "row=$rownum fld=$fld fldname=$fldname 
value=$flddata<BR>";
                        $dArray[$fldname] = $flddata;
                        $dArray[$fld] = $flddata;
                }
                while (list ($key, $val) = each ($dArray)) 
                        echo "$key=$val ";
                echo "<BR>";
                return $dArray;
        }

SUGGESTED RESOLUTION

1. In the query specification, select duplicate field names individually and 
use the AS keyword to specify a name that doesn't have an underscore in it.

2. Change any table field names that have underscores to remove them.

-- 
=======================================================================
Patrick Dunford, Christchurch, NZ - http://pdunford.godzone.net.nz/

   Do not be anxious about anything, but in everything, by prayer
and petition, with thanksgiving, present your requests to God.
    -- Philippians 4:6
http://www.heartlight.org/cgi-shl/todaysverse.cgi?day=20010406
=======================================================================
Created by Mail2Sig - http://pdunford.godzone.net.nz/software/mail2sig/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to