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
4
votes
1 answer

What does the dollar sign ('$') mean when in the string to .query?

What does the $ sign mean in this statement: // SQL Query > Update Data client.query('UPDATE items SET text=($1), complete=($2) WHERE id=($3)', [data.text, data.complete, id]);
na3na3iss
  • 65
  • 1
  • 1
  • 10
4
votes
1 answer

how to use node pg in AWS Lambda?

UPDATE/SOLVED ... the problem was that pgpass plugin was looking for $HOME/.pgpass, and $HOME wasn't defined on lambda, causing failure of join(undefined, '.pgpass'). Not really worth crediting myself with an answer for that .... I have the…
shaunc
  • 5,317
  • 4
  • 43
  • 58
4
votes
1 answer

Parameterized query with string literal in node-postgres

I'm trying to write a node-postgres query that takes an integer to use in an interval as a parameter: const query = { text: `SELECT foo FROM bar WHERE DATE(created_at) >= DATE(NOW()) - INTERVAL '$1…
alexroussos
  • 2,671
  • 1
  • 25
  • 38
4
votes
1 answer

How do I check if a table exists?

In db/index.js: const { Pool } = require('pg'); //node-postgres const pool = new Pool; module.exports = { query: (text, params, callback) => { return pool.query(text,params,callback); } }; In my main.js: const db =…
Rahul Iyer
  • 19,924
  • 21
  • 96
  • 190
4
votes
1 answer

Parameterized query in Postgresql with a json array

I would like to invoke array_prepend into a json[] using a parameterized query. I am using pg-promise npm package but this uses the normal node-postgres adapter under the hood. My query is: db.query(`update ${schema}.chats set messages = …
arisalexis
  • 2,079
  • 2
  • 21
  • 42
4
votes
1 answer

Is it possible to get the SQL statement together with the error returned by node-postgres?

I get errors that look like this from node-postgres (when calling its client.query method): { [Error: syntax error at or near "as"] severity: 'ERROR', code: '42601', position: '60', file: 'scan.l', line: '1044', routine: 'scanner_yyerror' }…
Alex Korban
  • 14,916
  • 5
  • 44
  • 55
4
votes
1 answer

Unable to install the node-postgres node.js module

Please, observe: c:\Work\if\server>npm install pg npm WARN package.json passport@0.1.15 No README data npm WARN package.json passport-http@0.2.1 No README data npm http GET https://registry.npmjs.org/pg npm http 304 https://registry.npmjs.org/pg npm…
mark
  • 59,016
  • 79
  • 296
  • 580
4
votes
1 answer

How do transactions work with node-postgres?

I'm using node-postgres to make SQL queries with callback style. I have a function that takes in a list of queries and executes them within a transaction block. My understanding is that I submit the query "BEGIN" using node-postgres, submit all the…
ferson2020
  • 3,015
  • 3
  • 18
  • 26
3
votes
2 answers

How to import pg-types using ES6 syntax?

Could you provide an example for node-pg-types with the "import" statement and not "require" so that type translators get registered for node-postgres?
Andris
  • 4,392
  • 2
  • 20
  • 16
3
votes
1 answer

Can you keep a PostgreSQL connection alive from within a Next.js API?

I'm using Next.js for my side project. I have a PostrgeSQL database hosted on ElephantSQL. Inside the Next.js project, I have a GraphQL API set up, using the apollo-server-micro package. Inside the file where the GraphQL API is set up…
3
votes
2 answers

PG (Node-Postgres) Pool Hangs on Connect ... But Only Inside Gatsby?

NOTE: This is mainly a question about the pg or Node-PostgreSQL module. It has details from Gatsby and Postgraphile, but I don't need expertise in all three, just pg. I have a database that works great with a PostGraphile-using Express server. I…
machineghost
  • 33,529
  • 30
  • 159
  • 234
3
votes
1 answer

Node-postgres prepared statements with conditional arguments

Is there a way to query something where you hava many conditions that can be undefined (not required) const c = { id?: number type?: string } const sql = `SELECT * FROM smth WHERE id=$1 AND type=$2` query(sql , [c.id, c.type])
ZiiMakc
  • 31,187
  • 24
  • 65
  • 105
3
votes
3 answers

postgres: relation does not exist when the table clearly exists when calling from node.js

so I psql'd and created table users; CREATE TABLE users ( id integer NOT NULL, username text ); I am able to grab rows by doing SELECT * FROM users; However, when I use node.js with the library module pg to make calls I get the infamous…
user299709
  • 4,922
  • 10
  • 56
  • 88
3
votes
1 answer

pg-promise : Cancel a query initiated with pg-query-stream

I have a postgresql table fulled with thousands of time-series data each day. I have an app allowing user to retrieve those data. Queries can take up from 200ms to 30 sec depending on the time range, so these must be cancelable to avoid useless load…
Raphiki
  • 190
  • 3
  • 11
3
votes
1 answer

Slonik dynamic insert query via sql tag

Via Slonik I try to create a sql statement in a dynamic way. I have a list of keys I want to use for my insert statement and to create a list of values. This is an example of my setup. Though the definition of my insert columns always fails. const…
Hoetmaaiers
  • 3,413
  • 2
  • 19
  • 29