From: Roland K. <r.k...@ya...> - 2008-06-01 14:51:09
|
hi, I tried to insert unicode-values into a PostGreSQL-array, but unfortunately that did not work but raised an UnicodeEncodeError (see below). so: - is is right, that pyPgSQL doesn't support unicode in arrays? - if yes, how can this be solved? here's the examle: assume the following PostGreSQL-table: CREATE TABLE test ( arr varchar[] ); now in python: >>> from pyPgSQL import PgSQL >>> db = PgSQL.connect(database='test', user='test', password='test', client_encoding=('UTF-8','ignore'), unicode_results=1) >>> cu = db.cursor() >>> cu.execute(u"""INSERT INTO test (arr) VALUES(%s)""", PgSQL.PgArray([u'ä'])) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/pyPgSQL/PgSQL.py", line 3086, in execute parms = tuple(map(_quote, self.__unicodeConvert(parms))); File "/usr/lib/python2.4/site-packages/pyPgSQL/PgSQL.py", line 2257, in _quote return value._quote() File "/usr/lib/python2.4/site-packages/pyPgSQL/PgSQL.py", line 1328, in _quote return _handleArray(self.value) File "/usr/lib/python2.4/site-packages/pyPgSQL/PgSQL.py", line 2239, in _handleArray _j = '%s%s,' % (_j, PgQuoteString(str(_i), 1)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 0: ordinal not in range(128) inserting non-unicode values works: >>> cu.execute(u"""INSERT INTO test (arr) VALUES(%s)""", PgSQL.PgArray(['ä'])) regards, Roland |