Re: IMMUTABLE function to cast enum to/from text?

From: Philip Semanchuk <philip(at)americanefficient(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Joe Conway <mail(at)joeconway(dot)com>, PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: IMMUTABLE function to cast enum to/from text?
Date: 2022-11-10 23:33:36
Message-ID: 26B23DE4-1D92-4201-94B9-1E7FE243EB4B@americanefficient.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Nov 10, 2022, at 3:39 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Joe Conway <mail(at)joeconway(dot)com> writes:
>>
>> CREATE OR REPLACE FUNCTION mood2text(mood)
>> RETURNS text AS
>> $$
>> select $1
>> $$ STRICT IMMUTABLE LANGUAGE sql;
>
> Of course, what this is doing is using a SQL-function wrapper to
> lie about the mutability of the expression. Whether you consider
> that elegant is up to you ;-) ... but it should work, as long as
> you don't break things by renaming the enum's values.

Thanks Joe and Tom,
I’m comfortable lying to Postgres occasionally — never for evil, only for good of course. :-)

Cheers
Philip

In response to

Browse pgsql-general by date

  From Date Subject
Next Message 黄宁 2022-11-11 02:47:43 get table oid in GIN extracequery function
Previous Message Tom Lane 2022-11-10 20:39:08 Re: IMMUTABLE function to cast enum to/from text?