pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mischa POSLAWSKY <postgres@shiar.org>
To: pgsql-bugs@postgresql.org
Subject: plperl no longer provides string representations of composite values
Date: Sat, 29 Oct 2011 00:42:27 +0200
Message-ID: <20111028224227.GB4880@pearl.mediadesign.nl> (raw)

Composite types are converted to and from Perl hashes since commit
REL9_1_ALPHA4~146 (Convert Postgres arrays to Perl arrays on PL/perl input
arguments; 2011-02-17), but are not stringified as claimed by the commit
message and release notes (unless nested in an array).

To illustrate:

CREATE TYPE foo AS (bar INTEGER, baz TEXT);
DO $$ my $val = spi_exec_query(q< SELECT        ROW(42,'test')::foo   AS col >)->{rows}->[0]->{col}; elog(NOTICE, "$val ".ref($val)) $$ LANGUAGE plperl;
NOTICE:  HASH(0xb864a744) HASH
DO $$ my $val = spi_exec_query(q< SELECT ARRAY[ ROW(42,'test')::foo ] AS col >)->{rows}->[0]->{col}; elog(NOTICE, "$val ".ref($val)) $$ LANGUAGE plperl;
NOTICE:  {"(42,test)"} PostgreSQL::InServer::ARRAY

On pg 9.0 the expected (but unblessed) strings (42,test) and {"(42,test)"}
are returned respectively.

To make matters worse, received values cannot be used in queries because
spi_exec_prepared() simply ignores hash arguments:

# DO $$ my $q = spi_prepare('SELECT $1 AS col', 'foo'  ); elog(NOTICE, spi_exec_prepared($q,  { bar=>42, baz=>'test' } )->{rows}->[0]->{col}) $$ LANGUAGE plperl;
ERROR:  spi_exec_prepared: expected 1 argument(s), 0 passed at line 1.

Again except if nested in an array:

# DO $$ my $q = spi_prepare('SELECT $1 AS col', 'foo[]'); elog(NOTICE, spi_exec_prepared($q, [{ bar=>42, baz=>'test' }])->{rows}->[0]->{col}) $$ LANGUAGE plperl;
NOTICE:  {"(42,test)"}

While the intended feature would be very welcome as well, not being able
to convert to text is a serious regression.

Thanks and regards,
-- 
Mischa



view thread (3+ messages)  latest in thread

Message-ID: <20111028224227.GB4880@pearl.mediadesign.nl>
Permalink:  ../20111028224227.GB4880@pearl.mediadesign.nl/
Also on:    postgresql.org/message-id/20111028224227.GB4880@pearl.mediadesign.nl

 · 

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-bugs@postgresql.org
  Cc: postgres@shiar.org
  Subject: Re: plperl no longer provides string representations of composite values
  In-Reply-To: <20111028224227.GB4880@pearl.mediadesign.nl>
  References: <20111028224227.GB4880@pearl.mediadesign.nl>

* 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