JSON foreign keys in PostgreSQL

It is not possible, and may not ever be possible, to assign a foreign key to a json property. It’d be a major and quite complicated change to PostgreSQL’s foreign key enforcement. I don’t think it’s impossible to do, but would face similar issues to those experienced by the foreign-keys-to-arrays patch. With 9.4 it’ll be … Read more

How to fix “Error: The server does not support SSL connections” when trying to access database in localhost?

Here I provide a workaround for the question, and not the title of this post. A better answer to the post overall would probably address configuring SSL for the local machine. I arrived here trying to resolve the problem of finishing that Heroku tutorial mentioned in the question and setting up the Postgres database to … Read more

Pass a SELECT result as an argument to postgreSQL function

Pass the returned user_id set as array. Create the function to accept an integer array create function get_timeinstate ( user_id_set integer[], another_param… Then call it passing the array generated by array_agg get_timeinstate( ( select array_agg(userid) from “UserState” where ctime>’2014-07-14′::timestamp ), another_param ); Inside the function: where “UserState”.userid = any (user_id_set) BTW if you are using … Read more

Nodemon – “clean exit – waiting for changes before restart” during setup

There are a few things wrong with your code. You never told your app to run. When you’re ready creating your routes you should start your server with: app.listen(<port on which the server should run here>); Also you have an Express app and a router in the same file. The router should only be used … Read more

Open source column-oriented storage engine for PostgreSQL?

Citus Data has developed an open source columnar store extension for PostgreSQL. It is available under the Apache License v2.0. It supports PostgreSQL 9.3 and higher. First, creation the extension and a foreign server: CREATE EXTENSION cstore_fdw; CREATE SERVER cstore_server FOREIGN DATA WRAPPER cstore_fdw; Next, create some foreign tables: CREATE FOREIGN TABLE customer_reviews ( customer_id … Read more

Decode equivalent in postgres

There is an equivalent. It’s called a CASE statement. There are two forms of CASE: Simple CASE: CASE search-expression WHEN expression [, expression [ … ]] THEN statements [ WHEN expression [, expression [ … ]] THEN statements … ] [ ELSE statements ] END CASE; Searched CASE: CASE WHEN boolean-expression THEN statements [ WHEN … Read more