Created
July 3, 2017 11:44
-
-
Save dj-foxxy/16ba42d0a76da2bf384353cc024682b0 to your computer and use it in GitHub Desktop.
Array of composites passed to plpythonu function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ROLLBACK; | |
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment