-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix query decode when PostgreSQL encoding name does not match Python one
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.
- Loading branch information
Showing
6 changed files
with
47 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters