How to Disconnect from a database and go back to the default database in PostgreSQL?

It’s easy, just look the example. –my databases postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges ———–+———-+———-+———+——-+————————— francs | postgres | UTF8 | C | C | =Tc/postgres + | | | | | postgres=CTc/postgres + | | | | | francs=C*T*c*/postgres + | | | … Read more

Postgres ENUM data type or CHECK CONSTRAINT?

Based on the comments and answers here, and some rudimentary research, I have the following summary to offer for comments from the Postgres-erati. Will really appreciate your input. There are three ways to restrict entries in a Postgres database table column. Consider a table to store “colors” where you want only ‘red’, ‘green’, or ‘blue’ … 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

Store query result in a variable using in PL/pgSQL

I think you’re looking for SELECT select_expressions INTO: select test_table.name into name from test_table where id = x; That will pull the name from test_table where id is your function’s argument and leave it in the name variable. Don’t leave out the table name prefix on test_table.name or you’ll get complaints about an ambiguous reference.

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