在node.js中选择PostgreSQL时,可以找到错误的字符编码
我正在尝试使用node.js从PostgreSQL获取一些数据,但是当我使用SELECT *从表
中选择 *时,它会返回我错误的字符,但是在控制台中,它没有发生。
仅显示ASCII字符,但不显示UTF-8字符。我的整个数据库都是使用UTF-8编码的,我正在尝试更改node.js中的charset。
我尝试了:
await pgClient.query(`SET client_encoding = 'utf-8'`);
但是没有起作用。
这是bash中正在返回的内容的一个示例:
SELECT * FROM example; -- This returns "María"
但这是Node.js的响应:
await pgClient.query('SELECT * FROM example'); // This returns me "Mar¢a"
I'm trying to get some data from PostgreSQL using Node.js, but when I use SELECT * FROM table
it returns me wrong characters, but in console it didn't happen.
Only ASCII characters are shown, but not UTF-8 characters. My entire database is encoded using UTF-8, and I'm trying to change the charset in Node.js.
I tried this:
await pgClient.query(`SET client_encoding = 'utf-8'`);
But didn't work.
This is an example of what is returning in bash:
SELECT * FROM example; -- This returns "María"
But this is the response with Node.js:
await pgClient.query('SELECT * FROM example'); // This returns me "Mar¢a"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题只是一个窗口时刻。 Windows控制台可与Winxxxx编码一起使用,而Node.js中的PostgreSQL默认使用UTF8。
解决方案很简单,只需将您的
client_encoding
更改为utf8
或latin1
时,请使用终端:The problem was just a Windows moment. The Windows Console works with a WINXXXX encoding, while PostgreSQL in Node.js works with UTF8 by default.
The solution is simple, just change your
client_encoding
toUTF8
orLATIN1
while using the terminal: