simple query question to use with DBI selectall_hashref - Mailing list pgsql-general

From Kenji Morishige
Subject simple query question to use with DBI selectall_hashref
Date
Msg-id 20070705173931.GA28680@juniper.net
Whole thread Raw
Responses Re: simple query question to use with DBI selectall_hashref
List pgsql-general
I would like to create a query that returns a column with an integer
1 through (row_count) to use as the index while used in conjunction with
DBI's selectall_hashref($sql,$key) function.  In the past I'd usually just
write a wrapper around selectrow_hashref and put all those results in an
array. I don't know why DBI doesn't include a function like this.

if I could extract a pseudo column from the query itself with the result
order number, I could just use that as the key in selectall_hashref and sort
the results by key.

Is there a built-in function that returns the current row #?

select foo from bar;
row#;foo
----;-----
1;foodata1
2;foodata2
3;foodata3
4;foodata4

so I can pump it into:
my $hashref = $dbh->selectall_hashref($query);

print $hashref->{1}; # prints 'foodata1' etc

Or am I missing something and there is a way better way to do this...?

Sincerely,
Kenji

pgsql-general by date:

Previous
From: "A.M."
Date:
Subject: Re: [pgsql-general] In memory tables/databases
Next
From: "Nykolyn, Andrew"
Date:
Subject: Nested Transactions in PL/pgSQL