I recently upgraded to Postgres 9.6.1 and noticed pgp.helpers.insert is double quoting table name which results in relation does not exist error.
const data = {
resource_id: uuid.v4(),
data: {
content: 'some content'
},
version: 'application/vnd.integration.v2+json'
};
const stmt = pgp.helpers.insert(data, null, `${schema}.fake_entity_one`) + 'RETURNING id';
console.log(stmt);
cs.one(stmt).then(result => {
result.id.should.equal(1);
done();
});
This results in the query
insert into "tenant_00000000_0000_0000_0000_000000000000.fake_entity_one"("resource_id","data","version") values('64ab28aa-c173-4172-8d93-9ec5c598acb4','{"content":"some content"}','application/vnd.integration.v2+json')
If I remove the double quotes on table name, query works fine from the psql console. Any thoughts?
Since you are using a schema, the value for parameter table in your case must be of type [TableName]:
var table = new pgp.helpers.TableName(table, schema);
The method can also convert an object into [TableName] implicitely, i.e. you can do:
var insert = pgp.helpers.insert(data, null, {table, schema});
Perfect! Thanks @vitaly-t
Most helpful comment
Perfect! Thanks @vitaly-t