php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45610 pg_field_type returns wrong type
Submitted: 2008-07-23 19:33 UTC Modified: 2008-07-23 19:40 UTC
From: thuejk at gmail dot com Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 5.2.6 OS: Linux (probably all)
Private report: No CVE-ID: None
 [2008-07-23 19:33 UTC] 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"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-23 19:40 UTC] thuejk at gmail dot com
Ah bugger. It is because I have to use pg_field_num() instead of assuming the fields are numbered from 0 and up continuously.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 28 18:01:32 2024 UTC