Permission denied for relation in PostgreSQL

GRANT on the database is not what you need. Grant on the tables directly. Granting privileges on the database mostly is used to grant or revoke connect privileges. This allows you to specify who may do stuff in the database if they have sufficient other permissions. You want instead: GRANT ALL PRIVILEGES ON TABLE side_adzone … Read more

PostgreSQL cannot begin/end transactions in PL/pgSQL

A plpgsql function automatically runs inside a transaction. It all succeeds or it all fails. The manual: Functions and trigger procedures are always executed within a transaction established by an outer query — they cannot start or commit that transaction, since there would be no context for them to execute in. However, a block containing … Read more

How to create sequence if not exists

Postgres 9.5 or later IF NOT EXISTS was added to CREATE SEQUENCE in Postgres 9.5. That’s the simple solution now: CREATE SEQUENCE IF NOT EXISTS myschema.myseq; But consider details of the outdated answer anyway … And you know about serial or IDENTITY columns, right? Auto increment table column Postgres 9.4 or older Sequences share the … Read more

tech