From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jim Nasby <Jim.Nasby@bluetreble.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13960: plpython fails with certain function names
Date: Tue, 16 Feb 2016 20:49:38 -0500
Message-ID: <25529.1455673778@sss.pgh.pa.us> (raw)
In-Reply-To: <56C3CB9A.4030009@BlueTreble.com>
References: <20160215001447.2605.36302@wrigleys.postgresql.org>
<3868.1455497399@sss.pgh.pa.us>
<56C12241.2030107@BlueTreble.com>
<4535.1455498553@sss.pgh.pa.us>
<56C3CB9A.4030009@BlueTreble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Jim Nasby <Jim.Nasby@bluetreble.com> writes:
> On 2/14/16 7:09 PM, Tom Lane wrote:
>> Yeah, that's what I was thinking about. But yes, if we append the OID
>> anyway then we might as well just strip all non-alphanumeric chars
>> from the name. Safe and you still get some debuggability.
> Attached. I opted not to modify the name in-place. If it's safe to
> modify in place, might want to just replace invalid characters with '_'
> instead of making a copy.
I like the idea of replacing invalid characters with '_'. It's definitely
not safe to scribble on the pg_proc tuple, but we could get the same
result with a few wasted cycles by rescanning the procName string after
building it, as per attached.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:plpython_name_2.patch (text/x-diff, 3.7K) downloaddiff --git a/src/pl/plpython/expected/plpython_test.out b/src/pl/plpython/expected/plpython_test.outindex 7b76faf..f8270a7 100644
*** a/src/pl/plpython/expected/plpython_test.out
--- b/src/pl/plpython/expected/plpython_test.out
*************** select stupidn();
*** 16,23 ****
zarkon
(1 row)
! -- test multiple arguments
! CREATE FUNCTION argument_test_one(u users, a1 text, a2 text) RETURNS text
AS
'keys = list(u.keys())
keys.sort()
--- 16,23 ----
zarkon
(1 row)
! -- test multiple arguments and odd characters in function name
! CREATE FUNCTION "Argument test #1"(u users, a1 text, a2 text) RETURNS text
AS
'keys = list(u.keys())
keys.sort()
*************** for key in keys:
*** 27,34 ****
words = a1 + " " + a2 + " => {" + ", ".join(out) + "}"
return words'
LANGUAGE plpythonu;
! select argument_test_one(users, fname, lname) from users where lname = 'doe' order by 1;
! argument_test_one
-----------------------------------------------------------------------
jane doe => {fname: jane, lname: doe, userid: 1, username: j_doe}
john doe => {fname: john, lname: doe, userid: 2, username: johnd}
--- 27,34 ----
words = a1 + " " + a2 + " => {" + ", ".join(out) + "}"
return words'
LANGUAGE plpythonu;
! select "Argument test #1"(users, fname, lname) from users where lname = 'doe' order by 1;
! Argument test #1
-----------------------------------------------------------------------
jane doe => {fname: jane, lname: doe, userid: 1, username: j_doe}
john doe => {fname: john, lname: doe, userid: 2, username: johnd}
diff --git a/src/pl/plpython/plpy_procedure.c b/src/pl/plpython/plpy_procedure.cindex e1f5620..a0d0792 100644
*** a/src/pl/plpython/plpy_procedure.c
--- b/src/pl/plpython/plpy_procedure.c
*************** PLy_procedure_create(HeapTuple procTup,
*** 146,151 ****
--- 146,152 ----
MemoryContext cxt;
MemoryContext oldcxt;
int rv;
+ char *ptr;
procStruct = (Form_pg_proc) GETSTRUCT(procTup);
rv = snprintf(procName, sizeof(procName),
*************** PLy_procedure_create(HeapTuple procTup,
*** 155,160 ****
--- 156,170 ----
if (rv >= sizeof(procName) || rv < 0)
elog(ERROR, "procedure name would overrun buffer");
+ /* Replace any not-legal-in-Python-names characters with '_' */+ for (ptr = procName; *ptr; ptr++)+ {+ if (!((*ptr >= 'A' && *ptr <= 'Z') ||+ (*ptr >= 'a' && *ptr <= 'z') ||+ (*ptr >= '0' && *ptr <= '9')))+ *ptr = '_';+ }+
cxt = AllocSetContextCreate(TopMemoryContext,
procName,
ALLOCSET_DEFAULT_MINSIZE,
diff --git a/src/pl/plpython/sql/plpython_test.sql b/src/pl/plpython/sql/plpython_test.sqlindex c8d5ef5..3a76104 100644
*** a/src/pl/plpython/sql/plpython_test.sql
--- b/src/pl/plpython/sql/plpython_test.sql
*************** CREATE FUNCTION stupidn() RETURNS text A
*** 11,18 ****
select stupidn();
! -- test multiple arguments
! CREATE FUNCTION argument_test_one(u users, a1 text, a2 text) RETURNS text
AS
'keys = list(u.keys())
keys.sort()
--- 11,18 ----
select stupidn();
! -- test multiple arguments and odd characters in function name
! CREATE FUNCTION "Argument test #1"(u users, a1 text, a2 text) RETURNS text
AS
'keys = list(u.keys())
keys.sort()
*************** words = a1 + " " + a2 + " => {" + ", ".j
*** 23,29 ****
return words'
LANGUAGE plpythonu;
! select argument_test_one(users, fname, lname) from users where lname = 'doe' order by 1;
-- check module contents
--- 23,29 ----
return words'
LANGUAGE plpythonu;
! select "Argument test #1"(users, fname, lname) from users where lname = 'doe' order by 1;
-- check module contents
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: tgl@sss.pgh.pa.us, Jim.Nasby@bluetreble.com
Subject: Re: BUG #13960: plpython fails with certain function names
In-Reply-To: <25529.1455673778@sss.pgh.pa.us>
References: <20160215001447.2605.36302@wrigleys.postgresql.org> <3868.1455497399@sss.pgh.pa.us> <56C12241.2030107@BlueTreble.com> <4535.1455498553@sss.pgh.pa.us> <56C3CB9A.4030009@BlueTreble.com> <25529.1455673778@sss.pgh.pa.us>
* 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