Using psql to connect to PostgreSQL in SSL mode

psql below 9.2 does not accept this URL-like syntax for options. The use of SSL can be driven by the sslmode=value option on the command line or the PGSSLMODE environment variable, but the default being prefer, SSL connections will be tried first automatically without specifying anything. Example with a conninfo string (updated for psql 8.4) … Read more

how to exclude null values in array_agg like in string_agg using postgres?

With postgresql-9.3 one can do this; SELECT g.id, array_remove(array_agg(CASE WHEN g.canonical=”Y” THEN g.users ELSE NULL END), NULL) canonical_users, array_remove(array_agg(CASE WHEN g.canonical=”N” THEN g.users ELSE NULL END), NULL) non_canonical_users FROM groups g GROUP BY g.id; Update: with postgresql-9.4; SELECT g.id, array_agg(g.users) FILTER (WHERE g.canonical=”Y”) canonical_users, array_agg(g.users) FILTER (WHERE g.canonical=”N”) non_canonical_users FROM groups g GROUP BY g.id; … Read more

How to add “on delete cascade” constraints?

I’m pretty sure you can’t simply add on delete cascade to an existing foreign key constraint. You have to drop the constraint first, then add the correct version. In standard SQL, I believe the easiest way to do this is to start a transaction, drop the foreign key, add a foreign key with on delete … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)