pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedgeting results of query in plperl
2+ messages / 2 participants
[nested] [flat]
* geting results of query in plperl
@ 2020-03-06 12:57 stan <stanb@panix.com>
0 siblings, 1 reply; 2+ messages in thread
From: stan @ 2020-03-06 12:57 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
I have looked at:
https://www.postgresql.org/docs/8.4/plperl-database.html
I am also comfortable querying data from tables in perl. But I do not
quite see how to get the results of a query in plperl. Here is what I
tried, and it is not working:
my $rv2 = spi_exec_query('SELECT current_user');
my $user = $rv2->{rows}[1]->{my_column};
I have used this query in SQL functions, so I know it works. I also ran it
in plsql.
What do I have wrong here?
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: geting results of query in plperl
@ 2020-03-07 14:51 Andy Colson <andy@squeakycode.net>
parent: stan <stanb@panix.com>
0 siblings, 0 replies; 2+ messages in thread
From: Andy Colson @ 2020-03-07 14:51 UTC (permalink / raw)
To: stan <stanb@panix.com>; pgsql-general@lists.postgresql.org
On 3/6/20 6:57 AM, stan wrote:
> I have looked at:
>
> https://www.postgresql.org/docs/8.4/plperl-database.html
>
> I am also comfortable querying data from tables in perl. But I do not
> quite see how to get the results of a query in plperl. Here is what I
> tried, and it is not working:
>
> my $rv2 = spi_exec_query('SELECT current_user');
> my $user = $rv2->{rows}[1]->{my_column};
>
>
> I have used this query in SQL functions, so I know it works. I also ran it
> in plsql.
>
> What do I have wrong here?
>
It starts at zero:
> my $user = $rv2->{rows}[0]->{my_column};
Here is some live code:
my ($q, $i, $row, %map);
$q = spi_exec_query('select lower(username) as username, id from employee');
foreach $i (0.. $q->{processed} - 1)
{
$row = $q->{rows}[$i];
$map{ $row->{username} } = $row->{id};
}
$q = undef;
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2020-03-07 14:51 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06 12:57 geting results of query in plperl stan <stanb@panix.com>
2020-03-07 14:51 ` Andy Colson <andy@squeakycode.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox