summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-02-07 18:52:16 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-02-07 18:52:16 +0000
commitd596ecdc8b84a0de3be096a582ce08a172f0ad7a (patch)
treecbfaa6e885afea2adf2e011817cffabd8ee55df4
parent791befca186f4dc4d77908159a7ed991bd806252 (diff)
downloadpsycopg2-pg10.tar.gz
Don't convert '{}'::unknown into an empty listpg10
Close #506.
-rw-r--r--NEWS2
-rw-r--r--psycopg/typecast.c8
-rwxr-xr-xtests/test_types_basic.py10
3 files changed, 8 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index b87c110..33461e5 100644
--- a/NEWS
+++ b/NEWS
@@ -55,6 +55,8 @@ Other changes:
connection.
- `~connection.set_isolation_level()` will throw an exception if executed
inside a transaction; previously it would have silently rolled it back.
+- Empty arrays no more converted into lists if they don't have a type attached
+ (:ticket:`#506`)
What's new in psycopg 2.6.3
diff --git a/psycopg/typecast.c b/psycopg/typecast.c
index a4f123c..4fd92be 100644
--- a/psycopg/typecast.c
+++ b/psycopg/typecast.c
@@ -191,14 +191,6 @@ typecast_UNKNOWN_cast(const char *str, Py_ssize_t len, PyObject *curs)
Dprintf("typecast_UNKNOWN_cast: str = '%s',"
" len = " FORMAT_CODE_PY_SSIZE_T, str, len);
- // PostgreSQL returns {} for empty array without explicit type. We convert
- // that to list in order to handle empty lists.
- if (len == 2 && str[0] == '{' && str[1] == '}') {
- return PyList_New(0);
- }
-
- Dprintf("typecast_UNKNOWN_cast: fallback to default cast");
-
return typecast_default.cast(str, len, curs);
}
diff --git a/tests/test_types_basic.py b/tests/test_types_basic.py
index d17e529..b4a5f2c 100755
--- a/tests/test_types_basic.py
+++ b/tests/test_types_basic.py
@@ -166,12 +166,14 @@ class TypesBasicTests(ConnectingTestCase):
curs.execute("select col from array_test where id = 2")
self.assertEqual(curs.fetchone()[0], [])
- def testEmptyArray(self):
+ def testEmptyArrayNoCast(self):
s = self.execute("SELECT '{}' AS foo")
- self.failUnlessEqual(s, [])
- s = self.execute("SELECT '{}'::text[] AS foo")
- self.failUnlessEqual(s, [])
+ self.assertEqual(s, '{}')
s = self.execute("SELECT %s AS foo", ([],))
+ self.assertEqual(s, '{}')
+
+ def testEmptyArray(self):
+ s = self.execute("SELECT '{}'::text[] AS foo")
self.failUnlessEqual(s, [])
s = self.execute("SELECT 1 != ALL(%s)", ([],))
self.failUnlessEqual(s, True)