|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: thuejk at gmail dot com
New email:
PHP Version: OS:


 [2008-07-23 19:33 UTC] thuejk at gmail dot com
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:

$params = "host=localhost dbname=testdb user=testuser password=123456";

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);

foreach ($row as $field_name => $dummy) {
  $type = pg_field_type($res, $col_i++);
  if ($field_name == "c") {
    assert($type != "int4");



Expected result:
The type of column "c" should be "varchar"

Actual result:
The type of column "c" is "int4"


Add a Patch

Pull Requests

Add a Pull Request


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: Thu May 30 23:01:36 2024 UTC