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

