public inbox for [email protected]
help / color / mirror / Atom feedFrom: Adrian Klaver <[email protected]>
To: Celia McInnis <[email protected]>
To: pgsql-generallists.postgresql.org <[email protected]>
Subject: Re: adding a generated column to a table?
Date: Mon, 22 Apr 2024 09:16:26 -0700
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAGD6t7L3W=ftbvkrWRHwAAT0SAwdC0AWiw7oek7hRWMrBU9dUQ@mail.gmail.com>
References: <CAGD6t7L3W=ftbvkrWRHwAAT0SAwdC0AWiw7oek7hRWMrBU9dUQ@mail.gmail.com>
On 4/22/24 09:05, Celia McInnis wrote:
> 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(...
>
https://www.postgresql.org/docs/current/sql-createtable.html
GENERATED ALWAYS AS ( generation_expr ) STORED
So:
generated always as (DATE_PART('year', evtdate)::integer) STORED
--
Adrian Klaver
[email protected]
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], [email protected]
Subject: Re: adding a generated column to a table?
In-Reply-To: <[email protected]>
* 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