From: foxxy@foxdogstudios.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14730: Passing an array of composites to a plpythonu function results in a list of strs
Date: Mon, 03 Jul 2017 12:21:50 +0000
Message-ID: <20170703122150.1448.39204@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 14730
Logged by: Peter Sutton
Email address: foxxy@foxdogstudios.com
PostgreSQL version: 9.6.3
Operating system: Linux
Description:
Passing an array of composites to a plpythonu function results in a list of
strs, not a list of dicts or tuples as I expected. Here's an example:
BEGIN;
CREATE TABLE mytable (
col1 INTEGER
, col2 BOOLEAN
, col3 TEXT
);
INSERT INTO mytable VALUES
(1, TRUE , 'Text')
, (2, NULL , 'Text')
, (3, FALSE, NULL )
;
CREATE FUNCTION myfunc (ts mytable[]) RETURNS VOID
LANGUAGE plpythonu
AS $plpythonu$
from pprint import pformat
plpy.notice(pformat(ts))
if ts:
plpy.notice(type(ts[0]))
$plpythonu$;
SELECT myfunc(array_agg(t)) FROM mytable AS t;
-- psql:local/script.pgsql:28: NOTICE: ['(1,t,Text)', '(2,,Text)',
'(3,f,)']
-- psql:local/script.pgsql:28: NOTICE: <type 'str'>
-- myfunc
-- --------
--
-- (1 row)
SELECT myfunc(ARRAY[t]) FROM mytable AS t;
-- psql:local/script.pgsql:29: NOTICE: ['(1,t,Text)']
-- psql:local/script.pgsql:29: NOTICE: <type 'str'>
-- psql:local/script.pgsql:29: NOTICE: ['(2,,Text)']
-- psql:local/script.pgsql:29: NOTICE: <type 'str'>
-- psql:local/script.pgsql:29: NOTICE: ['(3,f,)']
-- psql:local/script.pgsql:29: NOTICE: <type 'str'>
-- myfunc
-- --------
--
--
--
-- (3 rows)
ROLLBACK;
https://gist.github.com/dj-foxxy/16ba42d0a76da2bf384353cc024682b0
I expected the items of list list to be tuple or dicts, e.g., [(1, True,
'Text'), ...].
Thanks, Peter.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: foxxy@foxdogstudios.com
Subject: Re: BUG #14730: Passing an array of composites to a plpythonu function results in a list of strs
In-Reply-To: <20170703122150.1448.39204@wrigleys.postgresql.org>
References: <20170703122150.1448.39204@wrigleys.postgresql.org>
* 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