ID: 45610 User updated by: thuejk at gmail dot com Reported By: thuejk at gmail dot com -Status: Open +Status: Bogus Bug Type: PostgreSQL related Operating System: Linux (probably all) PHP Version: 5.2.6 New Comment:
Ah bugger. It is because I have to use pg_field_num() instead of assuming the fields are numbered from 0 and up continuously. Previous Comments: ------------------------------------------------------------------------ [2008-07-23 19:33:30] thuejk at gmail dot com Description: ------------ For some queries, pg_field_type() returns the wrong field type. It seems to happen when you do a "SELECT *" and there are more than one table in the FROM-clause, with common columns eliminated. I tested with postgresql 7.4 and postgresql 8.1, with the same result. Reproduce code: --------------- <?php $params = "host=localhost dbname=testdb user=testuser password=123456"; pg_pconnect($params); pg_query("begin"); pg_query("CREATE TABLE test1(a integer)"); pg_query("CREATE TABLE test2(a integer, c varchar)"); pg_query("INSERT INTO test1 VALUES (1)"); pg_query("INSERT INTO test2 VALUES (1,'aa')"); $res = pg_query("SELECT * FROM test1 INNER JOIN test2 ON test1.a=test2.a"); $row = pg_fetch_assoc($res); $col_i=0; foreach ($row as $field_name => $dummy) { var_dump($field_name); $type = pg_field_type($res, $col_i++); var_dump($type); if ($field_name == "c") { assert($type != "int4"); } } pg_query("rollback"); ?> Expected result: ---------------- The type of column "c" should be "varchar" Actual result: -------------- The type of column "c" is "int4" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45610&edit=1