Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert postgres encoding to python ones #351

Merged
merged 2 commits into from
Mar 15, 2023
Merged

convert postgres encoding to python ones #351

merged 2 commits into from
Mar 15, 2023

Conversation

dlax
Copy link
Member

@dlax dlax commented Mar 9, 2023

Addresses second part of #348.

@dlax dlax force-pushed the encoding branch 5 times, most recently from 60e87aa to 179f09f Compare March 10, 2023 11:13
@dlax dlax marked this pull request as ready for review March 10, 2023 11:21
@dlax dlax requested a review from blogh March 10, 2023 11:21
pgactivity/pg.py Outdated Show resolved Hide resolved
PostgreSQL and Python have different names for encodings. Since we
retrieve PostgreSQL encoding name from
'pg_catalog.pg_encoding_to_char(pg_database.encoding)' and then use this
to decode Python bytes, we need to convert the former into a Python
encoding name.

We thus use psycopg._encodings.pg2pyenc() to translate encoding names;
this is not part of the public API of psycopg at the moment, but should
be in the future.

For psycopg2, we implement a fallback mechanism in pg.decode(); not
all PostgreSQL encodings will then be accounted for. Typically, from
https://www.postgresql.org/docs/current/multibyte.html#CHARSET-TABLE,
KOI8R, KOI8U and WIN* are not handled (as far as I can tell). (SQL_ASCII
is not handled either, but the fallback is enough.)

Test previously introduced using SQL_ASCII now passes. Additionally, we
add another test in which there is no mapping between Python and
PostgreSQL: zh_TW. In CI, we thus add zh_TW to the host locales.
@dlax dlax merged commit c815475 into master Mar 15, 2023
@dlax dlax deleted the encoding branch March 15, 2023 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants