|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #48721 Added parameter to pg_fetch_all allowing index to be column based
Submitted: 2009-06-29 15:31 UTC Modified: 2012-04-17 09:03 UTC
From: eric dot schultz at cyvon dot com Assigned: yohgaki (profile)
Status: Wont fix Package: PostgreSQL related
PHP Version: 5.2.10 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
48 - 46 = ?
Subscribe to this entry?

 [2009-06-29 15:31 UTC] eric dot schultz at cyvon dot com
I would love if the pg_fetch_all could take a parameter that would (optionally) allow the indexing of the resultset to be a column value as opposed to 0-based. (as many tables include a primary key/id)

Reproduce code:
From manual page:
I find myself doing the following VERY often:

$res = pg_query("Select * from set_options");
if(!$res) return(0);
$ret = array();
while($r = pg_fetch_assoc($res)){
    $ret[$r['id']] = $r; }

Expected result:
above produces an associative array indexed on the "id" column. Would like this built into the pg_fetch_all

Actual result:
see above


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-01 23:13 UTC]
-Package: Feature/Change Request +Package: PostgreSQL related
 [2012-03-31 06:01 UTC]
I think I marked the same request as "wont't fix". 
This sounds reasonable.
 [2012-03-31 06:01 UTC]
-Assigned To: +Assigned To: yohgaki
 [2012-04-17 09:03 UTC]
I forgot about compound keys. Therefore, it's simply cannot be done.

You can convert it with one line.

$res = array(array('id'=>1, 'a'=>'abc'), array('id'=>2, 'a'=>'xyz'));
array_walk($res, function($e, $k) use (&$new) {$new[$e['id']] = $e;});
 [2012-04-17 09:03 UTC]
-Status: Assigned +Status: Wont fix
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Oct 18 20:03:33 2021 UTC