Skip to content
Advertisement

Computed boolean column while creating table

I’m trying to create table with computed boolean values

But getting this error

Also I’ve tried with BIT instead BOOL – same error. Have no idea why it doesn’t work.

Advertisement

Answer

You need Postgres 12 (released 2019-10-03) if you want to use computed columns.

And as on its own is not enough. The syntax requires to use generated always as ... as documented in the manual:


If you are not using Postgres 12, then I would recommend to create a view that simply includes price <= 1000 as is_cheap as the calculation of that attribute is really cheap and there is no need to store it.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement