PostgreSQL

How to add a Auto Increment Column to a PostgreSQL table

H

Unfortunately Postgresql does not have Auto Increment columns so instead we create a Sequence that will act as a counter First we’ll need to create a sequence that we want to attch to our table CREATE SEQUENCE mytable_primary_id_seq; Then we need to assign the sequence to the column in our table that will act as the Autoincrement column ALTER TABLE mytable     ALTER COLUMN primary_id...

How to add a comment to a PostgreSQL table

H

If you have a table with the name transactions and you need to add a comment to this table for future references you can add a comment by using the code below, replacing the table name and the comment to suite your needs.

COMMENT ON TABLE "transaction" IS 'This table keeps a log of all orders that went through the website';

ERROR: permission denied for sequence

E

Problem: PHP Warning:  pg_query(): Query failed: ERROR:  permission denied for sequencename in PostgreSql
Solution:
To fix this problem, change the owner to the role that needs to access this sequence

ALTER TABLE sequencename OWNER TO rolename;

Change sequencename to your sequence name and rolename to the owner

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me