Search code examples
postgresqlpgadminpgadmin-4postgresql-16

How do I create a "GENERATED ALWAYS AS IDENTITY" or "GENERATED BY DEFAULT AS IDENTITY" column using the pgAdmin GUI in PostgreSQL?


I'm trying to figure out how I can add a GENERATED ALWAYS AS IDENTITY or GENERATED BY DEFAULT AS IDENTITY without needing to write SQL code.

I know I'm able to add them using code like this:

ALTER TABLE table_name 
ADD COLUMN id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY;

or

ALTER TABLE table_name 
ADD COLUMN id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY;

But is there perhaps a way to do it using the pgAdmin GUI tool instead of writing SQL as I would much rather prefer being able to do it using the GUI?

It seems like something that should be there, but I just can't find it. I tried searching on Google as well, but couldn't find anything useful with my searches.


Solution

  • Just as I was about to give up and finally post this question, I discovered the answer. So I'll post the answer here for others that are struggling to find it also.


    Right-click on your table and go to Properties..., then under the Columns tab, you'll be able to click on the Edit row button icon to find it:

    Create a "GENERATED ALWAYS AS IDENTITY" or "GENERATED BY DEFAULT AS IDENTITY" column using the pgAdmin GUI in PostgreSQL

    From here you can then set your column to be "GENERATED ALWAYS AS IDENTITY" or "GENERATED BY DEFAULT AS IDENTITY".