PostgreSQL: encoding problems on Windows when using psql command line utility
Thanks a lot Craig Ringer, works, finally works! You are my new idool now!
The steps are:
- open the cmd
SET PGCLIENTENCODING=utf-8
chcp 65001
psql -h your.ip.addr.ess -U postgres
PostgreSQL encoding issue while executing query from command line
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.
Wrong characters in columns after executing SQL file from psql.exe
You have mistakenly set your client encoding to WIN1252
when you imported an UTF-8 encoded file.
Run the following on your command line before starting psql
:
chcp 1252
set PGCLIENTENCODING=UTF8
If you want to view the data with psql
, you will have to reset the client encoding to WIN1252
.
Related Topics
SQL "Select Where Not in Subquery" Returns No Results
Aggregate Function in SQL Where-Clause
How to Scale Pivoting in Bigquery
Paging SQL Server 2005 Results
How to Perform Multiple Updates with a Single Update SQL Statement
Does Ms Access Support "Case When" Clause If Connect with Odbc
How to Run Native SQL with Entity Framework
Why Is a Udf So Much Slower Than a Subquery
How to Prevent a Database Trigger from Recursing
Extract Date (Yyyy/Mm/Dd) from a Timestamp in Postgresql
Merge Overlapping Date Intervals
Pls-00428: an into Clause Is Expected in This Select Statement
Create Custom Function for Date Difference Excluding Weekends and Holidays in Oracle SQL
Convert Date Format into Dd/Mmm/Yyyy Format in SQL Server
SQL Query to Find Nth Highest Salary from a Salary Table