2

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?

2

1 Answer 1

5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.