pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andy Colson <andy@squeakycode.net>
To: stan <stanb@panix.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: geting results of query in plperl
Date: Sat, 7 Mar 2020 08:51:35 -0600
Message-ID: <f24d1131-a477-f622-8152-39412b8152c1@squeakycode.net> (raw)
In-Reply-To: <20200306125755.GA3273@panix.com>
References: <20200306125755.GA3273@panix.com>

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;






view thread (2+ messages)

Message-ID: <f24d1131-a477-f622-8152-39412b8152c1@squeakycode.net>
Permalink:  ../f24d1131-a477-f622-8152-39412b8152c1@squeakycode.net/
Also on:    postgresql.org/message-id/f24d1131-a477-f622-8152-39412b8152c1@squeakycode.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: andy@squeakycode.net, stanb@panix.com
  Subject: Re: geting results of query in plperl
  In-Reply-To: <f24d1131-a477-f622-8152-39412b8152c1@squeakycode.net>
  References: <20200306125755.GA3273@panix.com> <f24d1131-a477-f622-8152-39412b8152c1@squeakycode.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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