Questions tagged [pg-promise]

Complete access layer to node-postgres via Promises/A+.

Built on top of node-postgres and its connection pool, this library translates their callback interface into one based on Promises/A+, while extending the protocol to a higher level, with automated connections and transactions management.

In addition, the library provides:

  • its own, more flexible query formatting;
  • event reporting for connectivity, errors, queries and transactions;
  • declarative approach to controlling query results;
  • support for all popular promise libraries.
521 questions
3
votes
1 answer

Filter CSV from pg-promise takes only the first value from array

My pg-promise query (2 ids in array passed in): db.any(`SELECT * FROM users WHERE user_id IN ($1:csv)`, team.member_ids) Console output of query and params passed to pg-promise: SELECT * FROM users WHERE user_id IN ($1:csv) [ 1, 2 ] //Fails one row…
Ron I
  • 4,090
  • 8
  • 33
  • 64
3
votes
1 answer

What is the reason for using GET instead of POST in this instance?

I'm walking through the Javascript demos of pg-promise-demo and I have a question about the route /api/users/:name. Running this locally works, the user is entered into the database, but is there a reason this wouldn't be a POST? Is there some sort…
user11965064
3
votes
1 answer

Usage of 'skip' option in multi-row update

I am new to NodeJs and tried to use pg-promise to do all the requests to my PG database. I want to be able to update columns dynamically, meaning sometimes I will update only two columns for a row, sometimes I will update all of them, etc ... My…
brownie
  • 33
  • 3
3
votes
1 answer

Relation not found error in multi-row insert with postgresql and pg-promise

I'm developing a nodejs project with a postgresql-db. I've created a schema for the db with some tables and now I've created a file with some prepared data (multilple rows) to insert. For that I followed the instructions of this entry: Multi-row…
Galadriel
  • 359
  • 5
  • 20
3
votes
1 answer

Read, Manipulate and Insert Data Efficiently using PG-Promise & PG-Query-Stream

I'm looking to do the following. Query a large table with a group by query to perform summarization of values. Run those records through a routine to add in some additional data Insert those into the DB efficiently. I've tried to do this using…
Paul Mowat
  • 61
  • 1
  • 6
3
votes
1 answer

Unparsed row in pg-promise when specifying SELECT columns

Why does pg-promise return a parsed object when querying with SELECT * ..., but returns an unparsed row when select columns are specified SELECT (given_name, family_name, photo) ...? Select all columns: db.oneOrNone(`SELECT * FROM $1~ WHERE…
ezorita
  • 126
  • 1
  • 9
3
votes
2 answers

Escape PostgreSQL string values

I'm trying to insert over 70k values to my postgres database. However, each rows have different types of special characters. When I insert I get the usual error. for example: syntax error at or near ".5". I'm using the module pg-promise. Below the…
Blinhawk
  • 379
  • 2
  • 7
  • 19
3
votes
1 answer

Using a cursor with pg-promise

I'm struggling to find an example of using a cursor with pg-promise. node-postgres supports its pg-cursor extension. Is there a way to use that extension with pg-promise? I'm attempting to implement an asynchronous generator (to support…
sdc395
  • 255
  • 1
  • 3
  • 12
3
votes
2 answers

Best practise to define a PostgreSQL database connection variable globally in a node.js web application?

I am creating a node and express REST application with a PostgreSQL database. My question is how to define the connection variable globally in a minimalist express application (for a Hello World example)? I have the following file structure with the…
alextc
  • 3,206
  • 10
  • 63
  • 107
3
votes
2 answers

two phase commit in nodeJS application

I am currently working on a nodeJS application that will soon need to write simultaneously on two PostgreSQL databases. This is meant for redudancy purposes: the writing operations must be made in the same time on both databases, or rollbacked if…
The Once-ler
  • 220
  • 3
  • 16
3
votes
1 answer

How to set columns when using helpers in pg-promise

Developed by node.js. I am using pg-promise. There is a problem with inserting the following data. I want to insert multiple rows of data into the table below. create table info ( id varchar(20) not null, name varchar(20) not null, createdate…
bamgae
  • 301
  • 1
  • 2
  • 15
3
votes
1 answer

Avoid SQL injection while inserting a mix of hard-coded and variable values?

I'm writing database queries with pg-promise. My tables look like this: Table "public.setting" │ user_id │ integer │ not null │ visualisation_id │ integer │ not null …
Richard
  • 62,943
  • 126
  • 334
  • 542
3
votes
1 answer

Postgres LISTEN / NOTIFY with pg-promise

I am trying to setup a simple LISTEN/NOTIFY functionality in PostgreSQL and notify node.js code using pg-promise library. The pg code I have scaffolded is CREATE OR REPLACE FUNCTION notify_trigger() RETURNS trigger AS $$ DECLARE BEGIN RAISE NOTICE…
Piyush Mehta
  • 53
  • 1
  • 8
3
votes
1 answer

node.js pg-promise and pagination from API

Looking at https://github.com/vitaly-t/pg-promise/wiki/Data-Imports there's a very detailed doc on how to use it for importing. However while that works for the demoed scenario I don't know how to apply it on my case. When I do my web call, I get…
Alin
  • 14,809
  • 40
  • 129
  • 218
3
votes
2 answers

PostgreSQL RETURNING fails with REGEXP_REPLACE

I'm running PostgreSQL 9.4 and are inserting a lot of records into my database. I use the RETURNING clause for further use after an insert. When I simply run: ... RETURNING my_car, brand, color, contact everything works, but if I try to use…
Michael Nielsen
  • 1,194
  • 3
  • 22
  • 37