Hi,
I can't figure out how to specify character encoding of the database. My database uses iso-8859-1 instead of utf8. All the strings I get from the database are considered utf8, and contain some "strange" characters. Is there any way to specify the encoding for automatic conversion?
I use the following connection string:
"postgres://myusername@localhost/mydbname"
I tried the following with no success:
"postgres://myusername@localhost/mydbname?encoding=iso-8859-1"
Thanks!
Alex
I got a workaround: I "surround" my real query in the following SQL query:
client.query("SET client_encoding to 'latin1';" , function(err, empty_result_to_fix_encoding) {
client.query("SELECT ...", function (err, result) { /* ... */ }); // "Real" query goes here.
});
Client or Pool configuration object is not very well documented. Complete (afaik) accepted params are like these I suppose. I'm using Node.js 5.9+.
const pg = require('pg');
const Pool = require('pg-pool'); // pg.Pool was undefined for some reason
const Promise = require('bluebird'); // or some other Promise implementation
const Client = pg.Client;
config = {
user: 'postgres',
password: '123456',
host: 'db.mydomain.com',
port: 5432,
database: 'myDb',
client_encoding: 'utf8', // This is not documented, I discovered it via inspecting "https://github.com/iceddev/pg-connection-string"
ssl: true,
max: 20,
min: 1,
idleTimeoutMillis: 1000,
Client: Client, // This is client constructor, can be interchanged with native client
Promise: Promise // This is internally used promise constructor
};
var pool = new Pool(config);
// Go on with your new pool
Most helpful comment
I got a workaround: I "surround" my real query in the following SQL query: