How to make connection to Postgres via Node.js

Here is an example I used to connect node.js to my Postgres database. The interface in node.js that I used can be found here https://github.com/brianc/node-postgres var pg = require(‘pg’); var conString = “postgres://YourUserName:YourPassword@localhost:5432/YourDatabase”; var client = new pg.Client(conString); client.connect(); //queries are queued and executed one after another once the connection becomes available var x = … Read more

Where does PostgreSQL store the database?

To see where the data directory is, use this query. show data_directory; To see all the run-time parameters, use show all; You can create tablespaces to store database objects in other parts of the filesystem. To see tablespaces, which might not be in that data directory, use this query. SELECT *, pg_tablespace_location(oid) FROM pg_tablespace;

How do I get a column with consecutive, increasing numbers, without having any numbers missing?

Adapted this from a previous answer. This kind of stuff happens often when applications want a tabbing-order for variables (read: records in an EAV model) , which could also be (part of) an alternate key. the priority field needs to be kept consecutive. [this is the tabbing-order] on INSERT: all records with priority >= the … Read more

CONSTRAINT to check values from a remotely related table (via join etc.)

CHECK constraints cannot currently reference other tables. The manual: Currently, CHECK expressions cannot contain subqueries nor refer to variables other than columns of the current row. One way is to use a trigger like demonstrated by @Wolph. A clean solution without triggers: add redundant columns and include them in FOREIGN KEY constraints, which are the … Read more