DB/PostgreSQL

[psycopg2] Checking encoding type of table

See_the_forest 2022. 9. 28. 11:14

The encoding are support in PostgreSQL allows us to store text in a variety of encodings, including single-bytes encoding and multiple-byte encoding. All supported encoding can be used transparently by clients and server.

 

We can find encoding of table in PostgresSQL by inspecting the connection.encoding parameters. To change encoding, there is a method called connection.set_client_encoding().

 

import psycopg2
conn = psycopg2.connect("dbname=db user=ur")
cursor = conn.cursor()

encoding = conn.encoding
print(f"Current encoding is {encoding}")

# Convert encoding into other
conn.set_client_encoding('EUC-KR')

 

 

Source from : https://www.postgresql.org/docs/current/multibyte.html