simple query question to use with DBI selectall_hashref

From: Kenji Morishige <kenjim(at)juniper(dot)net>
To: pgsql-general(at)postgresql(dot)org
Cc: kenjim(at)juniper(dot)net
Subject: simple query question to use with DBI selectall_hashref
Date: 2007-07-05 17:39:31
Message-ID: 20070705173931.GA28680@juniper.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Amiel 2007-07-05 17:43:46 Way to determine index bloat stats?
Previous Message Nykolyn, Andrew 2007-07-05 17:34:09 Nested Transactions in PL/pgSQL