From: Philip Semanchuk <philip@americanefficient.com>
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: IMMUTABLE function to cast enum to/from text?
Date: Thu, 10 Nov 2022 14:52:24 -0500
Message-ID: <EBFE2A74-B421-4494-8FCC-9F072F128188@americanefficient.com> (raw)
Hi all,
I know that Postgres' enum_in()/enum_out() functions have a volatility class of STABLE, and STABLE is required because enum elements can be renamed. We have an enum in our database used in a number of custom functions, all of which require casting the enum to/from text. Since enum_in() and enum_out() are STABLE, that means our functions that rely on those casts must also be STABLE, and as a result we can't use them in generated columns.
I have seen conversations that suggest creating a custom IMMUTABLE function to perform the cast, but I can't figure out how to do that except with a CASE statement that enumerates every possible value. Is there a more elegant approach?
Thanks
Philip
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: philip@americanefficient.com
Subject: Re: IMMUTABLE function to cast enum to/from text?
In-Reply-To: <EBFE2A74-B421-4494-8FCC-9F072F128188@americanefficient.com>
References: <EBFE2A74-B421-4494-8FCC-9F072F128188@americanefficient.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox