Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1otDbL-0002NP-A6 for pgsql-general@arkaria.postgresql.org; Thu, 10 Nov 2022 19:52:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1otDbH-0002Jk-Ve for pgsql-general@arkaria.postgresql.org; Thu, 10 Nov 2022 19:52:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1otDbH-0002Ja-I0 for pgsql-general@lists.postgresql.org; Thu, 10 Nov 2022 19:52:35 +0000 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1otDbA-0007Vu-Nt for pgsql-general@lists.postgresql.org; Thu, 10 Nov 2022 19:52:34 +0000 Received: by mail-qt1-x82d.google.com with SMTP id c15so1581860qtw.8 for ; Thu, 10 Nov 2022 11:52:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=americanefficient-com.20210112.gappssmtp.com; s=20210112; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:from:to:cc:subject:date:message-id:reply-to; bh=J+GfLb69rTr1UPe4bn6d9TZ6zyKY2xnGo5p2d4wu/5s=; b=QH54NTocf8tfSA0/fJaJKBfC8ZVNkEBF2k+vlmhUGbHjKUbfe5ToztCkLL0nlloykr 7PL2yfqBNuDX+hQxy/EWQiHDjorzdDPpZDKGw/n43npWWvdCFT2w/pWjcBPSfdhuZCsJ bxujxHrwUuwAet/YS0VQZrSLbmm+YukXgfmfIGhItwcj5yj5+XXZYIw3ENvdBgjCwaHn AwIiV9+zvN89XA2ZVkBBcD22c8IFOUHNeEaFUARjBEqKpGkMxR5JXCsBIa1iWnnY84BT 4z0NksKq5yEUbrreuHOTVCsiS7hikUX2EJ4dxdj29nS8vAPCYwMolWBV5hH5C7ZkUa9b GNAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=J+GfLb69rTr1UPe4bn6d9TZ6zyKY2xnGo5p2d4wu/5s=; b=RbxhDfcC8Wt0Oahxv8zQ4pHiInTg/9+HEUVRt9lzlH+GA2L9ts8qsk/ECgv+tDm4MY xx8JdI19EIDoU+0QcZbie23E4BC7Rcn5Hc1Qgq5lO+BB0fEoIMO4wfx4W1igy4efV6qv rXdZ4qOn+xtzTfBiHYVPmjnUe/A0siV+g7cvlXshd2laAXuu0kX7tyVeCb8zViNrASGw Em7c+RwHZCEQjCvGK+OYBzLNCnoENmnxD/3/R6uUZt6IjPJD1N2Y6Y/AFs6UVpQ44wKz hnKOG3Rz8+5udKl3IkeJBDt8lxhbnxkvfFue5qLaesaQBZ6Jhghw5IK4HyZmXfFexJXx lVRw== X-Gm-Message-State: ACrzQf1k+NOAzNUVRYB4WLu0q36lroK0UJ1Q7vjdoxKGQ3c2BIXGT920 MIVN1aC1sanUABSLjG1JULksgk3Dw3CHf/u6kwS8PH9/kpV8GTOwNR0mR/cNA55F0Ey/+yh55tZ U6VDXu9i8T8TsqGfY3xwvei2nHFD4hBoIsY+UZqNYK02jrj7y3vp+ZdavLsO1/0whM9PKxZCODv 8O2IYq/QzEAEqf8zAfsYPMSQ== X-Google-Smtp-Source: AMsMyM5OPdX4QKm+6vPt8CSrJTVSIrzyYez6/gLcOkRK856JbpsLlyCAPw+G42NemC3XDfLAxeCsTg== X-Received: by 2002:ac8:7f0c:0:b0:39d:a20:1d39 with SMTP id f12-20020ac87f0c000000b0039d0a201d39mr53750982qtk.164.1668109945821; Thu, 10 Nov 2022 11:52:25 -0800 (PST) Received: from smtpclient.apple ([24.211.149.51]) by smtp.gmail.com with ESMTPSA id q6-20020a37f706000000b006ed61f18651sm147001qkj.16.2022.11.10.11.52.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Nov 2022 11:52:25 -0800 (PST) From: Philip Semanchuk Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: IMMUTABLE function to cast enum to/from text? Message-Id: Date: Thu, 10 Nov 2022 14:52:24 -0500 To: PostgreSQL General X-Mailer: Apple Mail (2.3696.120.41.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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.=20 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=20 Philip=