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.

450 questions
85
votes
7 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
  • 38,081
  • 8
  • 81
  • 91
62
votes
1 answer

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
  • 49,649
  • 117
  • 410
  • 768
40
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
  • 3,640
  • 16
  • 58
  • 106
39
votes
8 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
  • 984
  • 1
  • 7
  • 15
31
votes
6 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,128
  • 2
  • 13
  • 27
28
votes
3 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
  • 2,709
  • 4
  • 17
  • 30
20
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
  • 2,676
  • 4
  • 19
  • 32
17
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,088
  • 2
  • 26
  • 56
17
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
  • 550
  • 3
  • 17
15
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
  • 20,421
  • 5
  • 85
  • 117
15
votes
5 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
  • 9,002
  • 19
  • 50
  • 110
14
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
  • 143
  • 1
  • 1
  • 5
13
votes
2 answers

ECONNREFUSED when making GET request in app, but API returns JSON successfully

I'm writing a node app with React, using node-postgres and superagent for backend calls. Let's say I'm making a GET request and using the JSON it returns to fill a table of students. My API looks like this: import pg from 'pg'; import Router from…
johnprisco
  • 143
  • 1
  • 1
  • 7
12
votes
2 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
  • 427
  • 1
  • 5
  • 15
11
votes
2 answers

node-postgres transactions with callbacks or async/await?

I'm running Node 7.6.0, which supports async/await. The node-postgres client pool supports async/await, and has a nice example here. However, the example for transactions in node-postgres (here) uses callbacks instead of async/await. Despite that…
Rob Johansen
  • 4,576
  • 7
  • 37
  • 68
1
2 3
29 30