Node-postgres is a postgresql client module for node.js applications to interact with postgresql databases.
1
vote
0answers
19 views
Timestamptz, same point in time but different representation for same query with 'set local time zone'
I am trying to build my web app that will store the data on a PostgreSQL database server running on some location on Earth and will have users connecting from other locations, so probably different ...
5
votes
3answers
3k views
node-postgres: how to prepare a statement without executing the query?
I want to create a "prepared statement" in postgres using the node-postgres module. I want to create it without binding it to parameters because the binding will take place in a loop.
In the ...
0
votes
1answer
93 views
Nodejs server disconnecting after idle for too long (ECONNRESET)
Good day,
I have the following issue:
my node.js server which is running node-postgres to communicate with a database gives the error read ECONNRESET when a client asks for it to query the database.
...
2
votes
1answer
48 views
Reusing pg-pool via module exports
After reading the docs: https://github.com/brianc/node-pg-pool, I am slightly concerned about reusing the new Pool() method.
The docs suggests that I need to place the new Pool() before exports and ...
1
vote
1answer
14 views
Knex saves date incorrectly
I have a date field set with table.date('day'); in knex schema. When I insert it with knex('table_name').insert({ someOtherData, day: '2016-08-14'}) and then use knex.select('day').from('table_name') ...
2
votes
1answer
46 views
How to convert MySQL-style question mark `?` bound parameters to Postgres-style `$1` bound parameter
I am converting an existing project from MySQL to Postgres. There are quite a few raw SQL literals in the code that use ? as a placeholder, e.g.
SELECT
id
FROM
users
WHERE
name = ?
...
0
votes
1answer
26 views
node-postgres: Update more than one record at once
I'm building an app in node.js using node-postgres. I don't know how to update more than one record at once. Here is my code:
var status = 20;
var id = [23,12,43];
pool.connect(function(err, client, ...
0
votes
1answer
27 views
PostgreSQL node.js prepared statements maximum bindings
I am trying to do some big bulk inserts to Postgres via node-postgres
When the bindings array exceeds 65536 values then passes to postgres the rest of values and when the query it runs I take the ...
0
votes
0answers
51 views
Not able to connect to PostgreSQL via NodeJS
Below is the connection details
exports.DB_NAME = "postgres";
exports.DB_USERNAME = "abcd";
exports.DB_PASSWORD = "abcd1234";
exports....
5
votes
3answers
4k views
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,...
1
vote
4answers
2k views
How to make a synchronous query (blocking call) with node-postgres?
While booting my Node.js app, I want to make a couple of synchronous calls to the PostgreSQL database to check some things before continuing the control flow. How can I achieve this using the node-...
0
votes
1answer
36 views
Postgres: Cannot connect from NodeJS (PG) with md5
Node v6.2 on Windows 10; PG (node-postgres) v4.4.2
Postgres 9.5 on Ubuntu 14.04 Trusty VirtualBox
I'm using the PG (node-postgres) module to connect to Postgres on Ubuntu in a virtual machine. I was ...
0
votes
1answer
62 views
(node) warning: possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit
I am using pg node module for connecting database. I have been creating multiple connection for each DML operation. when continuous query execution takes place
I got warning message as "(node) ...
23
votes
5answers
10k views
node-postgres: how to execute “WHERE col IN (<dynamic value list>)” 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 ...
0
votes
0answers
21 views
Can I use node-postgres or sequelize with nginx?
Will there be any problem with the multiple instances that nginx might create of my webserver and the connection pool?
I'm asking because of this particular quote I found on sequelize documentation:
...
1
vote
3answers
31 views
(node-postgres, pg) Proper insertion of table name
How does one correctly provide the table name if the name can be dynamically determined and still prevent SQL injection attacks?
For example:
The following works but I believe is insecure:
dbclient....
2
votes
1answer
37 views
How to get data that was createdAt or updatedAt 30 seconds from the the current time PostgreSQL
I'm trying to access data from a table that was created or updated data 30 seconds from the current time. Does anyone have any good idea of how to do this efficiently? I'm using node.js and pg package ...
0
votes
0answers
21 views
node+node-postgres+postgres insert into from select not working in trigger
I have a problem I do not understand.
I have a trigger on insert in one of my tables. This trigger is working perfectly if I insert the data in my table from the psql command line.
Now I normally do ...
1
vote
2answers
85 views
Omiting column names / inserting objects directly into node-postgres
I'd like to pass dictionaries with column names as keys, thus avoiding declaring the column names within the query itself (typing them directly).
Assume I have a table User with 2 column names:
...
1
vote
3answers
43 views
PostgreSQL lead() issue with camelCase column
So I'm trying to query a time card table whose structure is like this
employeeId | clockInTime| clockOutTime
-----------+------------+--------------
555 | 1462797450 | 1462785465
555 | ...
1
vote
2answers
122 views
postgres:get executable query from query with parameters
Is there any way to get executable query from query with $ parameters.Actually its weird but i want to store executable query in database.A complete query without parameters($1,$2,$3)
i am using node-...
3
votes
3answers
771 views
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', '[email protected]'], callBack)
This approach automatically comments out any ...
-1
votes
1answer
92 views
for loop inside query
I have this in mongo:
//fill QueryString
collection.find({"myID" : {$in:QueryString} },{}).toArray(function(err, Stuff) {
...
var flag = true;
for (var i=0; i<Stuff.length; i++) {
//if ...
0
votes
1answer
34 views
from mongo to postgresql - error: syntax error at or near “array_to_string”
I am trying to learn databases and nodejs.
I want to ask how can I translate the following from mongod to postgresql using nodejs.
//fill QueryString
collection.find({"myID" : {$in:QueryString} },{})...
3
votes
2answers
2k views
node-postgres 'event emitter style' vs 'callback style'
node-postgres states the following:
node-postgres supports both an 'event emitter' style API and a 'callback' style. The
callback style is more concise and generally preferred, but the evented ...
2
votes
4answers
1k views
Mass insert into Postgres with brianc/node-postgres
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 ...
0
votes
1answer
82 views
Node-Postgres: program does not work after 30 seconds while using Express, no problems without Express
I am using node-postgres to connect to a Postgres database from NodeJS; it gives a strange error Cannot read property 'rows' of undefined after running the program for 30 seconds (after the first ...
3
votes
1answer
414 views
Why can't I delete from db using node-postgres?
Is there something special i need to do with a parameterized query?
the following seems to succeed (i'm using a promise-ified client.query see end),
console.log('cancel for', data);
var ...
0
votes
1answer
46 views
out parameter result returns by node pg module - postgresql
I have created a procedure in postgresql as below.
CREATE OR REPLACE FUNCTION public.functiontest2(
IN data numeric,
OUT result numeric,
OUT result1 numeric)
RETURNS record AS
$BODY$
...
2
votes
2answers
183 views
Node calling postgres function with temp tables causing “memory leak”
I have a node.js program calling a Postgres (Amazon RDS micro instance) function, get_jobs within a transaction, 18 times a second using the node-postgres package by brianc.
The node code is just an ...
0
votes
0answers
33 views
How to print Postgresql schema via node-postgres or Knex.js
How to print Postgresql schema via node-postgres or Knex.js? Ideally, I would like to have a schema.sql that is generated by Knexjs migration like what Ruby's ActiveRecord does.
8
votes
2answers
5k views
node-postgres with massive amount of queries
I just started playing around with node.js with postgres, using node-postgres. One of the things I tried to do is to write a short js to populate my database, using a file with about 200,000 entries.
...
-1
votes
3answers
143 views
node-postgres : query not executing in sequence
i have kept insert & update code in 2 different files and based on condition
always insert should execute first and then update.but somehow update executes first then insert
test.js : ...
1
vote
1answer
771 views
Webpack can not use __dirname?
I am trying to use node-postgres to hook my app up to Postgres. The code I use is:
import React from 'react';
import pg from 'pg';
import fs from 'fs';
var cn = {
host: 'localhost', // server name ...
0
votes
2answers
77 views
Postgresql: I can connect with the command line but not with node-postgres
When I use the CLI to connect to my database, everything works fine.
psql dbname postgres
psql ask me for the password I set before (with ALTER) and I get connected.
In my pg_hba.conf file I get ...
3
votes
2answers
69 views
Why does Node.js Postgres Wiki example insert multiple records per http request?
We are using the node-postgres (pg on NPM) for our app but were having issues so we decided to go back to the examples on the Wiki:
https://github.com/brianc/node-postgres/wiki/Example
When we ...
5
votes
4answers
3k views
Manually promisifying pg.connect with Bluebird
I want to promisify node-postgres' pg.connect method along with the inner connection.query method provided in the callback.
I can .promisify the latter, but I need to implement the first one manually ...
2
votes
3answers
3k views
Pass array from node-postgres to plpgsql function
The plpgsql function:
CREATE OR REPLACE FUNCTION testarray (int[]) returns int as $$
DECLARE
len int;
BEGIN
len := array_upper($1);
return len;
END
$$ language plpgsql;
The node-...
1
vote
1answer
19 views
Insert into table after pg dump
I used pg_dump to populate a table in new database. After that, I want to be able to insert rows into table using the default autoincrementer of the serial key. Here is what I have in table:
In this ...
1
vote
1answer
174 views
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(...
2
votes
1answer
214 views
Node-postgres Inserting a new record into my database does not return the new entry's data
Here's the route from which the query is being executed:
userRouter.route("/new")
.post(function (req, res) {
var user = req.body;
pg.connect(connectionString, function (error, ...
0
votes
1answer
49 views
Array of type enum coming back as string from Postgres
Given a custom enum:
CREATE TYPE vehicle AS ENUM ('car', 'truck', 'bicycle');
And a table like so:
CREATE TABLE vehicle_events (
timestamp timestamptz NOT NULL DEFAULT current_timestamp,
labels ...
2
votes
0answers
80 views
When should I call done() in node-postgres?
pg 4.4.3
I'm using socket.io to connect client-side to server. I've guessed, I suppose to connect server to database on server start, but there are a lot of warnings in pg "docs": 'use done() or bad ...
1
vote
0answers
154 views
This socket has been ended by the other party] code: 'EPIPE'
I'm receiving this error after some actions, for example, in ~10 seconds after successful insert:
Error: This socket has been ended by the other party] code: 'EPIPE'
Means, first time i'm ...
2
votes
1answer
213 views
Node function on AWS Lambda can't connect to database with node-pg
My function works locally, but, when I deploy to AWS Lambda, it can't seem to connect to my postgres database. Here's the error:
{ [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: '...
0
votes
2answers
55 views
From express + pg to reusable code : help refactoring
So, I have some node code to deal with and I’m hoping someone here can help me refactor it. This is express + pg:
app.get('/path', function (req, res, next) {
pg.connect(connectionString, function(...
1
vote
1answer
136 views
querying postgres db with node-postgres
Do I need to use pg.connect() every time I query the database? After looking over the githhub page and wiki, the examples show a query inside the pg.connect callback like this (the comments are from ...
0
votes
1answer
2k views
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 ...
2
votes
0answers
63 views
Node.js postgres UTF connect string
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 ...
0
votes
2answers
264 views
prepared statements node-postgresql error with null result
i am new in node.js and postgresql. am allready connected with postgres db and execute some test code. after am going to use prepared statements.am create a sample login script. if user exist it ...