Open jumpnett opened 1 year ago
Thanks for reporting @jumpnett. If you're able to submit a PR, it will be very welcome.
I'm experiencing the same error. Adding a few logs, I can see that pg_catalog
name is bytes in my Postgres (v15) installation.
I can replicate the error on my setup too. Thank you. @j-bennet
Details: Server: PostgreSQL 12.11 (Ubuntu 12.11-0ubuntu0.20.04.1) PgCli version: 3.5.0
This may be occurring because your database/client's encoding is set to SQL_ASCII (which will prevent the underlying postgres library, psycopg, from decoding strings to Python str objects). Quick example:
import psycopg
# Assuming you have PG* env vars set
with psycopg.connect() as conn:
result = conn.execute("SHOW SERVER_ENCODING").fetchone()
print(result)
result = conn.execute("SELECT 'str'").fetchone()[0]
print(conn.info.encoding, result, type(result))
with psycopg.connect("client_encoding=utf8") as conn:
result = conn.execute("SHOW SERVER_ENCODING").fetchone()
print(result)
result = conn.execute("SELECT 'str'").fetchone()[0]
print(conn.info.encoding, result, type(result))
(b'SQL_ASCII',)
ascii b'str' <class 'bytes'>
('SQL_ASCII',)
utf-8 str <class 'str'>
A workaround for the issue was to force the client encoding to utf8 via an environment variable when launching pgcli like so
PGCLIENTENCODING=utf8 pgcli
This isn't really a permanent solution, as it could result in trying to decode undecodable text from your database (since SQL_ASCII means it could contain anything, that's why psycopg won't decode it by default).
As a full fix, It's probably reasonable for pgcli to force its own decoding of returned bytes in specific cases like this where it's essentially fetching postgres identifiers (in this case, the elements of the search path) which I would always expect to be decodable. Instead of doing its own decoding, pgcli could also temporarily set the client encoding to utf8 or similar (e.g. SET client_encoding TO utf8
) so that psycopg decodes the results
Description
When launching pgcli, I get the following error:
This error occurs when connecting to a PostgreSQL 9.3.4, but not a PostgreSQL 9.3.20 server.
Your environment
OS: Ubuntu 23.04 x86_64 pgcli Version: 3.5.0 pip freeze: