Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jAann-0000Ta-Qm for pgsql-general@arkaria.postgresql.org; Sat, 07 Mar 2020 14:51:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jAanm-0000hl-Ja for pgsql-general@arkaria.postgresql.org; Sat, 07 Mar 2020 14:51:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jAanm-0000gY-9N for pgsql-general@lists.postgresql.org; Sat, 07 Mar 2020 14:51:42 +0000 Received: from squeakycode.net ([96.126.114.205]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jAank-0006xM-9x for pgsql-general@lists.postgresql.org; Sat, 07 Mar 2020 14:51:41 +0000 Received: from rogue.localdomain (unknown [204.141.212.80]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (1024 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: andy) by squeakycode.net (Postfix) with ESMTPSA id 73C8C22821; Sat, 7 Mar 2020 08:51:37 -0600 (CST) Subject: Re: geting results of query in plperl To: stan , pgsql-general@lists.postgresql.org References: <20200306125755.GA3273@panix.com> From: Andy Colson Message-ID: Date: Sat, 7 Mar 2020 08:51:35 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200306125755.GA3273@panix.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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;