PL/Python: Fix hint about returning composite type from Python
authorPeter Eisentraut
Fri, 30 Jun 2017 20:51:14 +0000 (16:51 -0400)
committerPeter Eisentraut
Fri, 30 Jun 2017 20:51:14 +0000 (16:51 -0400)
('foo') is not a Python tuple: it is a string wrapped in parentheses.  A
valid 1-element Python tuple is ('foo',).

Author: Daniele Varrazzo 

src/pl/plpython/expected/plpython_composite.out
src/pl/plpython/plpy_typeio.c

index 7fc6a928e72a803fe2093cbb30f8e912df09ae2b..af801923343d6ef5746e09bcb8d734240eba588b 100644 (file)
@@ -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"
index b2db8940a0a27e8a56a8f76c8569f7c8c9b5a7a6..4dfa3e8f915bc7ce308aedfcd0709499d063c456 100644 (file)
@@ -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.")));
            }