snippetsqlMinor
How to paste chinese characters in psql terminal?
Viewed 0 times
terminalchinesepsqlpastehowcharacters
Problem
I am trying to paste chinese characters into psql terminal:
When pasting into normal terminal (Max OS) it works fine:
What might be wrong?
$ psql
=> \encoding
=> UTF8
# Ctrl+v (艺术与设计)
=> ?????设计When pasting into normal terminal (Max OS) it works fine:
$ # Ctrl+v (艺术与设计)
$ 艺术与设计What might be wrong?
Solution
psql delegates the handling of input to a shared library, which is either libreadline or libedit.But
libedit used to not work reliably with multibyte character sets, as has been reported on multiple occasions, here for OSX for example.From your comment:
/Library/PostgreSQL/9.4/bin/psql -> libedit@1.47.0 does not work, /Library/PostgreSQL/9.4/bin/psql -> libedit@1.48.0 does not work BUT /Applications/Postgres.app/Contents/Versions/9.4/bin/psql -> libedit@3.0.0 works!...it seems that by relinking to a newer version, you were able to solve the problem. That's useful to know.
The reason why
libedit is used at all while libreadline did a better job first is that the latter is licensed under the GPL, whereas psql is BSD-licensed like the rest of PostgreSQL. A consequence is that psql cannot be shipped in compiled form with the necessary parts that call libreadline, without breaching its license. On the other hand libedit uses the BSD license, so it's OK to ship with it.The solution for psql packagers so far has been to ship PostgreSQL with
libedit and let the users relink it with libreadline if necessary.On Linux, the Debian/Ubuntu packages even do this dynamically without the user intervening.
Context
StackExchange Database Administrators Q#126981, answer score: 6
Revisions (0)
No revisions yet.