Given this UI in pgAdmin4, what's the difference between these two options:
IdentityGenerated
I'm from a SQL Server background, so I'm used to setting the IDENTITY of an INT, for those MSSql tables to auto-generate that column value.
How is this different/similar in Postgres?
What is interesting is when I check out the GENERATED option, I get this menu, now?

While the IDENTITY option looks like I need to specify everything. So is the difference that IDENTITY is very hard-coded specific, while the GENERATED is 'let me auto set everything up, except for some expression thingy?'
NOTE: Using the latest Docker image of Postgres, so let's assume v10+ (with regards to serial now being off the table in this discussion).
Similar questions:
Identity works the same way as in mssql or SQL in general, PostgreSQL 10+ used generated as identity more as a compliant on SQL standard, compared to the older serial. I think This answer explained it well here.
For GENERATED, It's a column that will always be created as a computed value from other columns.
Let's say monthly_salary GENERATED ALWAYS AS (salary/12) STORED will use value from salary column, calculate, and stored as monthly_salary. see The documentation here.
For syntax purposes, both are similar. But there is a little difference.\
# This one is IDENTITY
GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]
# This one is generated from other column
GENERATED ALWAYS AS ( generation_expr ) STORED
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With