From: Jim H. <ftp...@jo...> - 2003-06-20 20:17:31
|
Hello, I'm having trouble with Unicode. I have set up the database to use UTF-8. I am trying to get some non-ASCII strings in there and I am failing. Here is a short version of the script: -------------------------------------- #!/usr/bin/python -u # test unicode support in pyPgSQL import string; from pyPgSQL import libpq from pyPgSQL import PgSQL dBconnection=PgSQL.connect("::ctanWeb:ftpmaint:") dBcursor=dBconnection.cursor() dBcursor.execute("SELECT * FROM authors") print dBcursor.fetchone() # works fine; I'm connected # these two also work fine dBcursor.execute("INSERT INTO authors (name,email) VALUES ('Mike Jones','mik...@ct...')") dBcursor.execute("INSERT INTO authors (name,email) VALUES (%(name)s,%(email)s)",{'name':'Mike Jones','email':'mik...@ct...'}) # this does not work dBcursor.execute("INSERT INTO authors (name,email) VALUES ('Mike Schr\xf6der','mik...@ct...')") # I cannot get to run, even dBcursor.execute("INSERT INTO authors (name,email) VALUES (%(name)s,%(email)s)",{'name':u'Mike Schr\xf6der','email':u'mik...@ct...'}) ------------------------------------- The line that does not work gives me the error message: Traceback (most recent call last): File "./test_uni.py", line 25, in ? dBcursor.execute("INSERT INTO authors (name,email) VALUES ('Mike Schr\xf6der','mik...@ct...')") File "/usr/lib/python2.2/site-packages/pyPgSQL/PgSQL.py", line 2956, in execute raise OperationalError, msg libpq.OperationalError: ERROR: Unicode >= 0x10000 is not supoorted I cannot make it out: is that a PostgreSQL objection or does it come from PyPgSQL? (By the way, the 'supoorted' is not me.) So my questions are: (1) Is Pg unable to take this character? (2) What is the right format for a dictionary substitution? I can't get the final line past an ASCII encoding error: ordinal not in range. Thanks for any help at all; I tried looking in the archives of this list but I had no luck, Jim Hefferon |