adding a generated column to a table?

From: Celia McInnis <celia(dot)mcinnis(at)gmail(dot)com>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: adding a generated column to a table?
Date: 2024-04-22 16:05:39
Message-ID: CAGD6t7L3W=ftbvkrWRHwAAT0SAwdC0AWiw7oek7hRWMrBU9dUQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If I have a table containing a date field, say:
create temporary table tmp1 as select now()::date as evtdate;
SELECT 1

select DATE_PART('year', evtdate)::integer as year from tmp1;
year
------
2024
(1 row)

Is there some way of doing something like the following?:

alter table tmp1 add column year integer generated always as
DATE_PART('year', evtdate)::integer STORED;
ERROR: syntax error at or near "DATE_PART"
LINE 1: ... tmp1 add column year integer generated always as DATE_PART(...

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2024-04-22 16:16:26 Re: adding a generated column to a table?
Previous Message Adrian Klaver 2024-04-22 15:51:38 Re: CLUSTER vs. VACUUM FULL