Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
    
what os and client do you use? –  EveryEvery Oct 10 '13 at 8:53
    

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.