PostgreSQL encoding issue while executing query from command line

我与影子孤独终老i 提交于 2019-12-22 15:04:59

问题


I am trying to execute an SQL query which is stored in the file. I am using following command to execute:

psql -d DB_NAME -a -f QUERY_NAME.sql

I have some non English text in the SQL file like - સુરત

When the query is executed the text in the database looks like - à ª¸à «Âà ª°à ª¤

How do I execute the query from command line so that it runs correctly?


回答1:


Make sure the client_encoding matches the encoding of your file. Check your system locale. Then use a matching command line argument for psql. Quoting the manual here:

If at least one of standard input or standard output are a terminal, then psql sets the client encoding to "auto", which will detect the appropriate client encoding from the locale settings (LC_CTYPE environment variable on Unix systems). If this doesn't work out as expected, the client encoding can be overridden using the environment variable PGCLIENTENCODING.

Example for a Linux shell:

env PGCLIENTENCODING='WIN1258' psql DB_NAME -a -f QUERY_NAME.sql

List of available encodings in the manual.



来源:https://stackoverflow.com/questions/19290750/postgresql-encoding-issue-while-executing-query-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!