pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Fixed PL/Python hint about array of composites
4+ messages / 3 participants
[nested] [flat]

* Fixed PL/Python hint about array of composites
@ 2017-05-29 16:38  Daniele Varrazzo <daniele.varrazzo@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Daniele Varrazzo @ 2017-05-29 16:38 UTC (permalink / raw)
  To: pgsql-bugs

The error message hint suggests [('foo')]. ('foo') is not a valid
Python tuple: it's a literal with redundant parentheses. ('foo',) is a
valid tuple.

Patch to correct the hints and an occurrence in the test suite attached.

-- Daniele

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

0001-Fixed-hint-about-returning-composite-type-from-Pytho.patch (text/x-patch, 2.6K) download From 94ecee67014d2f58596774037f3f9c44c53367f1 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo <daniele.varrazzo@gmail.com> Date: Mon, 29 May 2017 17:32:57 +0100 Subject: [PATCH] Fixed hint about returning composite type from Python ('foo') is not a Python tuple: it is a string wrapped in parentheses. A valid 1-element Python tuple is ('foo',). --- src/pl/plpython/expected/plpython_composite.out | 2 +- src/pl/plpython/plpy_typeio.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pl/plpython/expected/plpython_composite.out b/src/pl/plpython/expected/plpython_composite.out index 7fc6a92..5ed18e1 100644 --- a/src/pl/plpython/expected/plpython_composite.out +++ b/src/pl/plpython/expected/plpython_composite.out @@ -589,6 +589,6 @@ $$ LANGUAGE plpythonu; SELECT * FROM composite_type_as_list_broken(); ERROR: malformed record literal: "first" DETAIL: Missing left parenthesis. -HINT: To return a composite type in an array, return the composite type as a Python tuple, e.g. "[('foo')]" +HINT: To return a composite type in an array, return the composite type as a Python tuple, e.g. "[('foo',)]" CONTEXT: while creating return value PL/Python function "composite_type_as_list_broken" diff --git a/src/pl/plpython/plpy_typeio.c b/src/pl/plpython/plpy_typeio.c index 0e04753..cb79b0d 100644 --- a/src/pl/plpython/plpy_typeio.c +++ b/src/pl/plpython/plpy_typeio.c @@ -949,7 +949,7 @@ PLyObject_ToDatum(PLyObToDatum *arg, int32 typmod, PyObject *plrv, bool inarray) (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("malformed record literal: \"%s\"", str), errdetail("Missing left parenthesis."), - errhint("To return a composite type in an array, return the composite type as a Python tuple, e.g. \"[('foo')]\""))); + errhint("To return a composite type in an array, return the composite type as a Python tuple, e.g. \"[('foo',)]\""))); } return InputFunctionCall(&arg->typfunc, @@ -1387,7 +1387,7 @@ PLyGenericObject_ToComposite(PLyTypeInfo *info, TupleDesc desc, PyObject *object (errcode(ERRCODE_UNDEFINED_COLUMN), errmsg("attribute \"%s\" does not exist in Python object", key), inarray ? - errhint("To return a composite type in an array, return the composite type as a Python tuple, e.g. \"[('foo')]\"") : + errhint("To return a composite type in an array, return the composite type as a Python tuple, e.g. \"[('foo',)]\"") : errhint("To return null in a column, let the returned object have an attribute named after column with value None."))); } -- 2.7.4
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: Fixed PL/Python hint about array of composites
@ 2017-05-29 16:43  Daniele Varrazzo <daniele.varrazzo@gmail.com>
  parent: Daniele Varrazzo <daniele.varrazzo@gmail.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Daniele Varrazzo @ 2017-05-29 16:43 UTC (permalink / raw)
  To: pgsql-bugs

Just noticed that the sentence is also missing the final full stop.
New patch attached.

On Mon, May 29, 2017 at 5:38 PM, Daniele Varrazzo
<daniele.varrazzo@gmail.com> wrote:
> The error message hint suggests [('foo')]. ('foo') is not a valid
> Python tuple: it's a literal with redundant parentheses. ('foo',) is a
> valid tuple.
>
> Patch to correct the hints and an occurrence in the test suite attached.
>
> -- Daniele

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

0001-Fixed-hint-about-returning-composite-type-from-Pytho.patch (text/x-patch, 2.6K) download From c0ea87b5dd57ef7f042f42d31c4e6d7c0d831bae Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo <daniele.varrazzo@gmail.com> Date: Mon, 29 May 2017 17:32:57 +0100 Subject: [PATCH] Fixed hint about returning composite type from Python ('foo') is not a Python tuple: it is a string wrapped in parentheses. A valid 1-element Python tuple is ('foo',). --- src/pl/plpython/expected/plpython_composite.out | 2 +- src/pl/plpython/plpy_typeio.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pl/plpython/expected/plpython_composite.out b/src/pl/plpython/expected/plpython_composite.out index 7fc6a92..1f8707f 100644 --- a/src/pl/plpython/expected/plpython_composite.out +++ b/src/pl/plpython/expected/plpython_composite.out @@ -589,6 +589,6 @@ $$ LANGUAGE plpythonu; SELECT * FROM composite_type_as_list_broken(); ERROR: malformed record literal: "first" DETAIL: Missing left parenthesis. -HINT: To return a composite type in an array, return the composite type as a Python tuple, e.g. "[('foo')]" +HINT: To return a composite type in an array, return the composite type as a Python tuple, e.g. "[('foo',)]". CONTEXT: while creating return value PL/Python function "composite_type_as_list_broken" diff --git a/src/pl/plpython/plpy_typeio.c b/src/pl/plpython/plpy_typeio.c index 0e04753..37ab362 100644 --- a/src/pl/plpython/plpy_typeio.c +++ b/src/pl/plpython/plpy_typeio.c @@ -949,7 +949,7 @@ PLyObject_ToDatum(PLyObToDatum *arg, int32 typmod, PyObject *plrv, bool inarray) (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("malformed record literal: \"%s\"", str), errdetail("Missing left parenthesis."), - errhint("To return a composite type in an array, return the composite type as a Python tuple, e.g. \"[('foo')]\""))); + errhint("To return a composite type in an array, return the composite type as a Python tuple, e.g. \"[('foo',)]\"."))); } return InputFunctionCall(&arg->typfunc, @@ -1387,7 +1387,7 @@ PLyGenericObject_ToComposite(PLyTypeInfo *info, TupleDesc desc, PyObject *object (errcode(ERRCODE_UNDEFINED_COLUMN), errmsg("attribute \"%s\" does not exist in Python object", key), inarray ? - errhint("To return a composite type in an array, return the composite type as a Python tuple, e.g. \"[('foo')]\"") : + errhint("To return a composite type in an array, return the composite type as a Python tuple, e.g. \"[('foo',)]\".") : errhint("To return null in a column, let the returned object have an attribute named after column with value None."))); } -- 2.7.4
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: Fixed PL/Python hint about array of composites
@ 2017-06-22 11:49  Heikki Linnakangas <hlinnaka@iki.fi>
  parent: Daniele Varrazzo <daniele.varrazzo@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Heikki Linnakangas @ 2017-06-22 11:49 UTC (permalink / raw)
  To: Daniele Varrazzo <daniele.varrazzo@gmail.com>; pgsql-bugs

On 05/29/2017 07:43 PM, Daniele Varrazzo wrote:
> On Mon, May 29, 2017 at 5:38 PM, Daniele Varrazzo
> <daniele.varrazzo@gmail.com> wrote:
>> The error message hint suggests [('foo')]. ('foo') is not a valid
>> Python tuple: it's a literal with redundant parentheses. ('foo',) is a
>> valid tuple.
>>
>> Patch to correct the hints and an occurrence in the test suite attached.

> -HINT:  To return a composite type in an array, return the composite type as a Python tuple, e.g. "[('foo')]"
> +HINT:  To return a composite type in an array, return the composite type as a Python tuple, e.g. "[('foo',)]".

Huh, that looks weird. Perhaps we should use an example with two-element 
tuple in the example, to avoid the awkward trailing comma?

Then again, it's a useful to have it in the example, exactly because 
it's not obvious what you need to do with a 1-element tuple. Or maybe 
use "[('foo', 'bar',)]" in the example?

Maybe this is well known to all Python programmers, and I'm worrying 
about nothing.. I'm not too familiar with Python.

- Heikki



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Fixed PL/Python hint about array of composites
@ 2017-06-30 20:58  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Daniele Varrazzo <daniele.varrazzo@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Peter Eisentraut @ 2017-06-30 20:58 UTC (permalink / raw)
  To: Daniele Varrazzo <daniele.varrazzo@gmail.com>; pgsql-bugs

On 5/29/17 12:43, Daniele Varrazzo wrote:
> Just noticed that the sentence is also missing the final full stop.
> New patch attached.

committed

> On Mon, May 29, 2017 at 5:38 PM, Daniele Varrazzo
> <daniele.varrazzo@gmail.com> wrote:
>> The error message hint suggests [('foo')]. ('foo') is not a valid
>> Python tuple: it's a literal with redundant parentheses. ('foo',) is a
>> valid tuple.
>>
>> Patch to correct the hints and an occurrence in the test suite attached.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2017-06-30 20:58 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-05-29 16:38 Fixed PL/Python hint about array of composites Daniele Varrazzo <daniele.varrazzo@gmail.com>
2017-05-29 16:43 ` Daniele Varrazzo <daniele.varrazzo@gmail.com>
2017-06-22 11:49   ` Heikki Linnakangas <hlinnaka@iki.fi>
2017-06-30 20:58   ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>

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