tk0miya / testing.postgresql

Apache License 2.0
290 stars 46 forks source link

client encoding #8

Closed nbonnotte closed 8 years ago

nbonnotte commented 8 years ago

How can I specify what the default client encoding should be?

I have tests that fail on a Jenkins server because the client encoding is SQLASCII instead of UTF8...

nbonnotte commented 8 years ago

Ok, I can just specify conn.set_client_encoding('UTF-8') with all my connections, but would it not be possible to have a correct default client encoding?

tk0miya commented 8 years ago

The database encoding is used for the client encoding by default. http://www.postgresql.org/docs/9.5/static/runtime-config-client.html#GUC-CLIENT-ENCODING

So you can change it using initidb_args::

>>> from testing.postgresql import Postgresql
>>> import psycopg2
>>> pgsql = Postgresql(initdb_args='-E=EUC_JP --locale=ja_JP.eucJP -U postgres -A trust')
>>> c = psycopg2.connect(**pgsql.dsn())
>>> c.encoding
'EUCJP'

Thanks,

tk0miya commented 8 years ago

Now, I close this issue. If you still have any problem, please reopen again.