node-postgres

How to set schema with node-postgres

大憨熊 提交于 2020-02-25 04:33:47
问题 I'm trying to query against a schema called DOCUMENT in my postgres db using node-postgres. I can't seem to get a query to run against the specified schema. This query runs fine directly against postgres using psql SELECT * FROM "DOCUMENT".document_metadata m LEFT OUTER JOIN "DOCUMENT".document_attributes a ON a.document_id = m.id This code produces the error below const query = `SELECT * FROM "DOCUMENT".document_metadata m LEFT OUTER JOIN "DOCUMENT".document_attributes a ON a.document_id = m

Bulk insert into Postgres with brianc/node-postgres

被刻印的时光 ゝ 提交于 2020-02-21 11:53:38
问题 I have the following code in nodejs that uses the pg (https://github.com/brianc/node-postgres) My code to create subscriptions for an employee is as such. client.query( 'INSERT INTO subscriptions (subscription_guid, employer_guid, employee_guid) values ($1,$2,$3)', [ datasetArr[0].subscription_guid, datasetArr[0].employer_guid, datasetArr[0].employee_guid ], function(err, result) { done(); if (err) { set_response(500, err, res); logger.error('error running query', err); return console.error(

How do I send in parameters in COPY TO-query in node-postgres

谁说我不能喝 提交于 2020-01-30 10:55:50
问题 Im doing a query to export results to CSV in postgres running on a ubuntu-server. The query gets called from a Node-API which is connecting to Postgres via the node-postgres-driver(https://node-postgres.com/). The query looks like this: var sqlText = 'Copy (SELECT company.name AS Company, SUM(sale.numbersold) AS NumberSold FROM SALE LEFT JOIN company ON company.companyid = sale.companyid WHERE sale.createdate BETWEEN $1 AND $2 GROUP BY company.name) To \'/tmp/test.csv\' With CSV HEADER

Error Relation does not exist

橙三吉。 提交于 2020-01-14 07:37:11
问题 I am getting a [error: relation "causes" does not exist] error from my node app. The relation does exist, I'm not sure what the problem is. I created the table with CREATE TABLE causes ( cause_id bigint NOT NULL default nextval('causes_cause_id_seq'::regclass), cause_name varchar(40) NOT NULL, goal integer, sponsor varchar(30), organization varchar(30), submitter varchar(30), address varchar(34), balance numeric ); This is the query that's giving the error: client = pg.connect

How do I use node-postgres in a server?

匆匆过客 提交于 2020-01-12 13:59:10
问题 I'm writing a Node.js web server that uses a Postgres database. I used to connect on each new request like this: app.get('/', function (req, res) { pg.connect(pgconnstring, function (err, client) { // ... }); }); But after a few requests, I noticed 'out of memory' errors on Heroku when trying to connect. My database has only 10 rows, so I don't see how this could be happening. All of my database access is of this form: client.query('SELECT * FROM table', function (err, result) { if (err) {

How do I use node-postgres in a server?

烂漫一生 提交于 2020-01-12 13:58:06
问题 I'm writing a Node.js web server that uses a Postgres database. I used to connect on each new request like this: app.get('/', function (req, res) { pg.connect(pgconnstring, function (err, client) { // ... }); }); But after a few requests, I noticed 'out of memory' errors on Heroku when trying to connect. My database has only 10 rows, so I don't see how this could be happening. All of my database access is of this form: client.query('SELECT * FROM table', function (err, result) { if (err) {

multiple column copy format postgresql Node.js

你离开我真会死。 提交于 2020-01-11 12:59:32
问题 I using postgres stream to insert record into postgres , for single column works fine , but what is ideal data format for copy for multiple columns code snippets var sqlcopysyntax = 'COPY srt (starttime, endtime) FROM STDIN delimiters E\'\\t\''; var stream = client.query(copyFrom(sqlcopysyntax)); console.log(sqlcopysyntax) var interndataset = [ ['1', '4'], ['6', '12.074'], ['13.138', '16.183'], ['17.226', '21.605'], ['22.606', '24.733'], ['24.816', '27.027'], ['31.657', '33.617'], ['34.66',

node-postgres UTF password bug

牧云@^-^@ 提交于 2020-01-04 07:29:59
问题 I'm using https://github.com/brianc/node-postgres pg module. Apparently I can't consume a Unicode password to connect to the db. From the same location psql with connection parameters goes OK. With Node.js, it gives ne password authentication failed for user . When I check with console.log() I see exactly what I expect. If I change a password to ASCII both in the db and the connection string, everything works well. But I need the old Unicode password to be consumed... I tried both https:/

node-postgres UTF password bug

梦想与她 提交于 2020-01-04 07:29:06
问题 I'm using https://github.com/brianc/node-postgres pg module. Apparently I can't consume a Unicode password to connect to the db. From the same location psql with connection parameters goes OK. With Node.js, it gives ne password authentication failed for user . When I check with console.log() I see exactly what I expect. If I change a password to ASCII both in the db and the connection string, everything works well. But I need the old Unicode password to be consumed... I tried both https:/

Passing array of custom type to postgres function from node-pg and SQL injection

好久不见. 提交于 2020-01-03 03:06:06
问题 CREATE TYPE phototable AS ( photoid integer, parentid integer, fileextension character varying(20), description text, tag character varying(100) ); CREATE FUNCTION addphotos( p_placeid integer , p_permissiontypeid integer , p_description text DEFAULT NULL::text , p_photos phototable[] DEFAULT NULL::phototable[]) BEGIN ........ END I am calling this function from node.js (using node-postres) by generating an SQL query. I want to avoid it and want to use parameterized queries because I think it