Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR5d1-00000000fiA-1Z4b for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 10:32:31 +0000 Received: from localhost ([127.0.0.1]:58040 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xR5cy-00000009zIO-3Fpe for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 10:32:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:49334) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xQy3I-00000008CdA-31wX for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 02:27:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xQy3G-00000000Nr2-2WQG for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 02:27:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=KcfUvo+uwj1WdyxhWCBCp9rULbh9kB9NyaapWy6BpmQ=; b=WtbVLTuTcOmcqvzSNYCrVPYZIi od+uVUpYF9r4yMLdWw2/mx6oIxhtpdnyuPOnSZvQjl4xZf7VIAEpi6Cda7A6zVkmHKpXUxV9T6pZN JK+HRzK5IOkKH8ZCFODtrn2zvtCRP1lmqjDqhTQ8HGFaUXI0lRIdziJiuws2R2n5OCt7pwES6bp4u iXMOv0eG93kWfnfLfTeczv57Z/cs+tvYMM9o01Sa80THVSaWWGuXMAu7tDGK0gwoXfaIjfgw46w00 XcqvUL0JTRGbjzpU9WsptbRSxXX3xZqcqGMfoyd51WnRy2SiDkHqSgcwvMgJLDJycEUHvIrybfZIs fvHwWtQg==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xQy3E-00000000p48-2uQx for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 02:27:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xQy3D-000000028xz-1EYu for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 02:27:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19862: Replacing a cast leaves prepared statements using the old cast function To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: imchifan@mail.com Reply-To: imchifan@mail.com, pgsql-bugs@lists.postgresql.org Date: Wed, 11 Nov 2026 02:26:05 +0000 Message-ID: <19862-084810a081ea79a3@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19862 Logged by: Faye Email address: imchifan@mail.com PostgreSQL version: Unsupported/Unknown Operating system: Linux/amd64 Description: =20 Dropping and recreating a user-defined cast with a different cast function does not invalidate a statement prepared while the original cast existed. After the replacement, direct execution uses the new function and returns v2, while the prepared statement silently continues to use the old function and returns v1. The prepared statement should use the current cast definition, as direct execution does. Both executions should therefore return v2 after the cast is replaced. How to repeat: \set ON_ERROR_STOP on DROP TYPE IF EXISTS cast_src CASCADE; DROP TYPE IF EXISTS cast_dst CASCADE; CREATE TYPE cast_src AS ENUM ('x'); CREATE TYPE cast_dst AS ENUM ('v1', 'v2'); CREATE FUNCTION cast_v1(cast_src) RETURNS cast_dst LANGUAGE SQL IMMUTABLE AS $$ SELECT 'v1'::cast_dst $$; CREATE FUNCTION cast_v2(cast_src) RETURNS cast_dst LANGUAGE SQL IMMUTABLE AS $$ SELECT 'v2'::cast_dst $$; CREATE CAST (cast_src AS cast_dst) WITH FUNCTION cast_v1(cast_src); PREPARE cast_stmt(cast_src) AS SELECT $1::cast_dst AS value; EXECUTE cast_stmt('x') \gset before_ DROP CAST (cast_src AS cast_dst); CREATE CAST (cast_src AS cast_dst) WITH FUNCTION cast_v2(cast_src); SELECT ('x'::cast_src)::cast_dst AS value \gset direct_ EXECUTE cast_stmt('x') \gset prepared_ SELECT :'before_value' AS initial_prepared_value, :'direct_value' AS direct_value_after_cast_replacement, :'prepared_value' AS prepared_value_after_cast_replacement, :'direct_value' =3D :'prepared_value' AS prepared_matches_direct; DEALLOCATE cast_stmt; DROP CAST (cast_src AS cast_dst); DROP FUNCTION cast_v1(cast_src); DROP FUNCTION cast_v2(cast_src); DROP TYPE cast_src; DROP TYPE cast_dst; The recorded result is: initial_prepared_value | direct_value_after_cast_replacement | prepared_value_after_cast_replacement | prepared_matches_direct ------------------------+-------------------------------------+------------= ---------------------------+------------------------- v1 | v2 | v1 | f (1 row) This is consistent with parse analysis retaining the originally selected cast function without invalidating the prepared statement when the cast catalog entry changes. The issue was reproduced on PostgreSQL 20devel. It was also reproduced separately on PostgreSQL 18.6 (Debian 18.6-1.pgdg13+2). Both environments were Linux/amd64. No server interruption or server-log error occurred. This occurs when a user-defined cast is replaced with one backed by a different function after a statement using that cast has been prepared.