public inbox for [email protected]  
help / color / mirror / Atom feed
From: Celia McInnis <[email protected]>
To: pgsql-generallists.postgresql.org <[email protected]>
Subject: adding a generated column to a table?
Date: Mon, 22 Apr 2024 12:05:39 -0400
Message-ID: <CAGD6t7L3W=ftbvkrWRHwAAT0SAwdC0AWiw7oek7hRWMrBU9dUQ@mail.gmail.com> (raw)

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(...


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: adding a generated column to a table?
  In-Reply-To: <CAGD6t7L3W=ftbvkrWRHwAAT0SAwdC0AWiw7oek7hRWMrBU9dUQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox