Questions tagged [node-postgres]

Node-postgres is a postgresql client module for node.js applications to interact with postgresql databases.

About

Node-postgres is a postgresql client module for node.js applications to interact with postgresql databases.

Its source code and wiki can be found on GitHub.

587 questions
122
votes
8 answers

node-postgres: how to execute "WHERE col IN ()" query?

I'm trying to execute a query like this: SELECT * FROM table WHERE id IN (1,2,3,4) The problem is that the list of ids I want to filter against is not constant and needs to be different at every execution. I would also need to escape the ids,…
lanzz
  • 42,060
  • 10
  • 89
  • 98
118
votes
2 answers

How can I choose between Client or Pool for node-postgres

From https://node-postgres.com/features/connecting , seems like we can choose between Pool or Client to perform query pool.query('SELECT NOW()', (err, res) => { console.log(err, res) pool.end() }) client.query('SELECT NOW()', (err, res) => { …
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
57
votes
9 answers

SSL for PostgreSQL connection nodejs

I am trying to connect to my Heroku PostgreSQL DB and I keep getting an SSL error. Does anyone have an idea on how to enable SSL in the connection string? postgres://user:pass@host:port/database; Been looking for it everywhere but it does not seem…
Stefan
  • 1,214
  • 1
  • 9
  • 17
50
votes
4 answers

when to disconnect and when to end a pg client or pool

My stack is node, express and the pg module. I really try to understand by the documentation and some outdated tutorials. I dont know when and how to disconnect and to end a client. For some routes I decided to use a pool. This is my code const pool…
slevin
  • 4,166
  • 20
  • 69
  • 129
46
votes
8 answers

How do I properly insert multiple rows into PG with node-postgres?

A single row can be inserted like this: client.query("insert into tableName (name, email) values ($1, $2) ", ['john', 'john@gmail.com'], callBack) This approach automatically comments out any special characters. How do i insert multiple rows at…
stkvtflw
  • 12,092
  • 26
  • 78
  • 155
40
votes
5 answers

Import sql file in node.js and execute against PostgreSQL

I'm looking for an efficient way to take a raw sql file and have it executed synchronously against a postgres database, akin to if you ran it through psql. I have an sql file which creates all databases, imports data, etc. I need to execute this…
rgareth
  • 3,377
  • 5
  • 23
  • 35
31
votes
8 answers

Authentication error when connecting to Heroku PostgreSQL database

I'm developing a Node.js application using PostgreSQL and hosting on Heroku. My problem is that I get an authentication error like so: 14:32:05 web.1 | { [error: no pg_hba.conf entry for host "193.40.244.196", user "username", database…
j0ntech
  • 1,158
  • 3
  • 13
  • 27
26
votes
4 answers

Use node-postgres to get Postgres "timestamp without timezone" in utc

I've got some timestamps stored as the Postgres type timestamp without time zone. I'll use the timestamp 2013-12-20 20:45:27 as an example. I'm intending that this represent a UTC timestamp. In psql, if I run the query SELECT start_time FROM…
Isaac Dontje Lindell
  • 3,246
  • 6
  • 24
  • 35
23
votes
1 answer

node-postgres vs pg-promise for Nodejs Application

I'm going to build a Nodejs application with Postgresql as back end. I'm not going to use ORMs like Sequelize due to poor documentation and performance problems or any other ORM - ORM is an anti-pattern. I found node-postgres and pg-promise are…
Abdisamad Khalif
  • 765
  • 2
  • 7
  • 19
22
votes
3 answers

Does pg (node-postgres) automatically sanitize data

I am using node-postgres for a production application and I am wondering if there is anything I should be concerned about? Is the data sanitized automatically by node-postgres? I couldn't find anything about it on the github page:…
Luke Schlangen
  • 3,722
  • 4
  • 34
  • 69
19
votes
4 answers

Node-postgres: named parameters query (nodejs)

I used to name my parameters in my SQL query when preparing it for practical reasons like in php with PDO. So can I use named parameters with node-postgres module? For now, I saw many examples and docs on internet showing queries like…
AnomalySmith
  • 597
  • 2
  • 5
  • 16
16
votes
3 answers

query.on is not a function

I am trying to learn how to use javascript to connect to a postgresql database but when I try to log a query to the console using query.on(...), I get a type error that says "query.on is not a function". I have searched extensively on how to resolve…
tvonk13
  • 163
  • 1
  • 1
  • 5
16
votes
1 answer

PostgreSQL tuple format

Is there any document describing the tuple format that PostgreSQL server adheres to? The official documentation appears arcane about this. A single tuple seems simple enough to figure out, but when it comes to arrays of tuples, arrays of composite…
vitaly-t
  • 24,279
  • 15
  • 116
  • 138
15
votes
1 answer

Can I import the node-postgres module (pg) or is it CommonJS only?

I have been writing most of my APIs in old-school JavaScript using const var = require('var'). I am now writing my first API in ES6 syntax including using import rather than require. I always use the node-postgres module const {Pool} = require('pg')…
SuperCatchyUsername
  • 375
  • 1
  • 5
  • 14
15
votes
2 answers

How to do a bulk insert with node-postgres

I am importing an excel file into a postgres database with express and node-pg Currently I am looping through the excel rows and executing an insert for every row but I feel it's not the right way: workbook.xlsx.readFile(excel_file).then(function ()…
Fabrizio Mazzoni
  • 1,831
  • 2
  • 24
  • 46
1
2 3
39 40