Re: geting results of query in plperl

From: Andy Colson <andy(at)squeakycode(dot)net>
To: stan <stanb(at)panix(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: geting results of query in plperl
Date: 2020-03-07 14:51:35
Message-ID: f24d1131-a477-f622-8152-39412b8152c1@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message stan 2020-03-07 14:55:11 RAISE ERROR
Previous Message Justin 2020-03-07 14:47:39 Re: Rules versus triggers