public inbox for [email protected]
help / color / mirror / Atom feedFrom: Steve Baldwin <[email protected]>
To: Celia McInnis <[email protected]>
Cc: pgsql-generallists.postgresql.org <[email protected]>
Subject: Re: is there an immutable function to switch from date to character?
Date: Thu, 25 Apr 2024 07:35:50 +1000
Message-ID: <CAKE1AibcG-cg54_UmCjc2=heFyks261v7m2F8R4mR3qwqVcRBw@mail.gmail.com> (raw)
In-Reply-To: <CAGD6t7+GykxBs=BVeg2un_rQOrjXz==pXt-UWFVTNCgeYCSB5A@mail.gmail.com>
References: <CAGD6t7+GykxBs=BVeg2un_rQOrjXz==pXt-UWFVTNCgeYCSB5A@mail.gmail.com>
On Thu, Apr 25, 2024 at 7:31 AM Celia McInnis <[email protected]>
wrote:
> create temporary table junk as select now()::date as evtdate;
>
> alter table junk add column chardate text GENERATED ALWAYS AS
> (to_char(evtdate,'YYYY-Mon-DD')) STORED;
>
> ERROR: generation expression is not immutable
>
> Maybe this is a hack but..
b2bcreditonline=# create temporary table junk as select now()::date as
evtdate;
SELECT 1
b2bcreditonline=# alter table junk add column chardate text GENERATED
ALWAYS AS (to_char(evtdate,'YYYY-Mon-DD')) STORED;
ERROR: generation expression is not immutable
b2bcreditonline=# create or replace function date_to_text(i_date in date)
returns text immutable language sql as $$ select to_char(i_date,
'YYYY-MM-DD') $$;
CREATE FUNCTION
b2bcreditonline=# alter table junk add column chardate text GENERATED
ALWAYS AS (date_to_text(evtdate)) STORED;
ALTER TABLE
b2bcreditonline=# select * from junk;
evtdate | chardate
------------+------------
2024-04-24 | 2024-04-24
(1 row)
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: is there an immutable function to switch from date to character?
In-Reply-To: <CAKE1AibcG-cg54_UmCjc2=heFyks261v7m2F8R4mR3qwqVcRBw@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