pg

Closing postgres (pg) client connection in node.js

你。 提交于 2019-12-11 07:35:50
问题 I have a script that I want to run on a scheduled basis in node. The script is not terminating and exiting. I suspect that this is because my database client is still open. var client = new pg.Client(conString); client.connect(); function registerBundle (innerHash, outterHash) { // some stuff here } var query = client.query("SELECT id, chain FROM mytable where \ state_ready = true and transaction_id='' "); query.on('row', function(row) { var chain = row['chain']; var pg_record = row['id'];

Using Node 'pg' library to connect to Amazon Redshift

孤街醉人 提交于 2019-12-11 02:54:20
问题 I am trying to connect my API to an instance of Redshift using the 'pg' library but I get the following error: Possibly unhandled error: SET TIME ZONE is not supported at Connection.parseE (/Users/henrylee/WebstormProjects/project-api/node_modules/pg/lib/connection.js:534:11) I know Redshift doesn't support the setting of timezone, but I don't really care about that. I can't seem to find any help about how to get past this issue, so any inout would be greatly appreciated. Thanks! 来源: https:/

pg gem install on Mac OS Lion with rvm

跟風遠走 提交于 2019-12-10 22:43:09
问题 212-178-13-214:~ igorfedoronchuk$ gem install pg Building native extensions. This could take a while... /Users/igorfedoronchuk/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:48: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777 ERROR: Error installing pg: ERROR: Failed to build gem native extension. /Users/igorfedoronchuk/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb checking for pg_config... yes Using config values from /usr/bin/pg

Upsert in Postgres using node.js

妖精的绣舞 提交于 2019-12-10 15:48:02
问题 I'm trying to do an insert or update in a postgres database using node.js with pg extension (version 0.5.4). So far I have this code: (...) client.query({ text: "update users set is_active = 0, ip = $1 where id=$2", values: [ip,id] }, function(u_err, u_result){ debug(socket_id,"update query result: ",u_result); debug(socket_id,"update query error: ",u_err); date_now = new Date(); var month = date_now.getMonth() + 1; if(!u_err){ client.query({ text: 'insert into users (id,first_name,last_name

pg.connect not a function?

帅比萌擦擦* 提交于 2019-12-10 12:39:30
问题 There appears to be a lot of documentation (e.g. https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js, but also elsewhere including this site) indicating that the proper method of connecting with the pg.js Node package is using pg.connect. However, I attempted (after previous problems with my actual code) to test by using the exact code shown on the aforementioned Heroku documentation: var pg = require('pg'); pg.defaults.ssl = true; pg.connect(process.env.DATABASE_URL

Not able to install pg gem on Ubuntu 12.10

安稳与你 提交于 2019-12-10 11:13:17
问题 I am using Ubuntu 12.10 64-bit and I have following packages installed : dpkg --get-selections | grep postgre output: postgresql postgresql-9.1 postgresql-client postgresql-client-9.1 postgresql-client-common postgresql-common postgresql-contrib postgresql-contrib-9.1 postgresql-server-dev-9.1 postgresql-server-dev-all libpq-dev libpq5 rvm 1.17.9 ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-linux] I am not able to install pg gem I am getting following error : ERROR: Error installing pg:

insert statement in postgres for data type timestamp without time zone NOT NULL,

孤街浪徒 提交于 2019-12-09 14:09:24
问题 Database noob alert: I am trying to insert into a postgres table. The field that I would like to insert in is called make_date . The field type is timestamp without time zone NOT NULL , How do I insert today's date in there? Like right now's date and time? Something like the below but I am unable to get the right datatype insert format for dateTime.now insert into inventory_tbl (make_date) values (dateTime.now) 回答1: In addition to C. Ramseyer's solution (which is right), if you always (or

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

跟風遠走 提交于 2019-12-09 07:44:25
问题 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 = new pg.Pool({ user: 'pooluser',host: 'localhost',database: 'mydb',password: 'pooluser',port: 5432}); pool.on('error', (err, client) => { console.log('error ', err); process.exit(-1); }); app.get('/', (req, res)=>{ pool.connect() .then(client =>

Prepared Statements Already Exists

假装没事ソ 提交于 2019-12-09 03:16:58
问题 I am trying to use the prepared statements in ruby with pg gem. This is how my statement looks like conn.prepare("insert_values", "insert into " + objectName + "(" + headerStr + ") values (" + prep_values + ")") conn.exec_prepared("insert_values", arr) I keep getting the error Prepared Statement insert_values already exists. How Do i Fix this?? Thanks 回答1: Try to run: conn.exec("DEALLOCATE name_of_prepared_statement") In your example: conn.exec("DEALLOCATE insert_values") Simple test and it

(node-postgres, pg) Proper insertion of table name

本秂侑毒 提交于 2019-12-08 17:45:24
问题 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.query("INSERT INTO " + table_name + " VALUES ($1, $2, $3)", [value_a, value_b, value_c]) What I would like equivalently (but does not work) is: dbclient.query("INSERT INTO $1 VALUES ($2, $3, $4)", [table_name, value_a, value_b, value_c]) Edit: I am using node-postgres : https://github.com/brianc