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.94.2) (envelope-from ) id 1ugLOg-001bpf-Jk for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Jul 2025 10:47:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ugLOf-006a2I-3y for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Jul 2025 10:47:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ugLOe-006a2A-P8 for pgsql-hackers@lists.postgresql.org; Mon, 28 Jul 2025 10:47:57 +0000 Received: from relay16.mail.gandi.net ([2001:4b98:dc4:8::236]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1ugLOb-001Bqn-2a for pgsql-hackers@postgresql.org; Mon, 28 Jul 2025 10:47:55 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 7332F44969; Mon, 28 Jul 2025 10:47:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=postgresfriends.org; s=gm1; t=1753699668; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dJ4z3wmx6oKJa2HNQIL5/TzXCb2QorJeQ3tgjW98EOk=; b=krx5SW73ohR33neGW+KUpyALQCbKcX6dB6Cpp+Obk7ROojo6vOwNM/qDpl1NvLzSmd/djF m3uywwvT8goFhtu0pS33ujkFQsG2JRO2fiaVnG6KWLpDJTvGRNK35AsIEgN8DSA4IuodF9 th98JBLhzHi72HkZ+1MmRPvEgw88T+hlSm5G1eGkcaiHC+ZsZ465tZkExv3ay6qkyxq5Ll 1IYqWNZnidfYckqdDUESRTTkbuQXsFWRph6c3QVHIS/3TFDAOa8x2FLryDRLBSRp2FRunz oNEld4njnigP9RBPBzHKb+3KBlgr2PEuIHbkxgVZmGY2hgSqUSM1cmpISZp0vg== Message-ID: <1b702de4-86b0-4144-a2d0-38266296894f@postgresfriends.org> Date: Mon, 28 Jul 2025 12:47:47 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: implement CAST(expr AS type FORMAT 'template') To: jian he Cc: PostgreSQL-development References: <4c358bf8-87e8-4760-83d5-a6f9fcd88907@postgresfriends.org> Content-Language: en-US From: Vik Fearing In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-GND-State: clean X-GND-Score: 0 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdeludeljecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucenucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddvjeenucfhrhhomhepgghikhcuhfgvrghrihhnghcuoehvihhksehpohhsthhgrhgvshhfrhhivghnughsrdhorhhgqeenucggtffrrghtthgvrhhnpeelteetkedtkefgueegueegtedtuefffefhffdvfedvjefhtefhgeeitdeugeevjeenucfkphepvdgrtddvmeekgedvkeemudduvgdtmedvjedtudemvgdurgefmeekrgefgeemgegrgegtmeeijeguugenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtvdemkeegvdekmeduudgvtdemvdejtddumegvudgrfeemkegrfeegmeegrgegtgemieejuggupdhhvghloheplgfkrfggieemvdgrtddvmeekgedvkeemudduvgdtmedvjedtudemvgdurgefmeekrgefgeemgegrgegtmeeijeguuggnpdhmrghilhhfrhhomhepvhhikhesphhoshhtghhrvghsfhhrihgvnhgushdrohhrghdpnhgspghrtghpthhtohepvddprhgtphhtthhopehjihgrnhdruhhnihhvvghrshgrlhhithihsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhg List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 28/07/2025 10:41, jian he wrote: > select oid, castsource::regtype, casttarget::regtype, > castfunc::regproc, castcontext, castmethod > from pg_cast > where casttarget::regtype::text in ('text') or > castsource::regtype::text in ('text'); > > As you can see from the query output, cast from other type to text or > cast from text to other type is not in the pg_cast catalog entry. > there are in type input/output functions. it will be represented as a > CoerceViaIO node. > see function find_coercion_pathway (src/backend/parser/parse_coerce.c > line:3577). This is the same issue I came across when I tried to implement it several years ago. > adding these pg_cast entries seems tricky. > for example: > (assume castsource as numeric, casttarget as text) > will > (castsource as numeric, casttarget as text, castfunc as numeric_out, > castformatfunc as numeric_to_char) > ever work? > but numeric_out' result type is cstring. I had been imagining another castcontext that would only specify the castfunc when the FORMAT claused is used, otherwise the current method of passing through IO would be used. > so I tend to think adding castformatfunc to pg_cast will not work. Perhaps not, but we need to find a way to make this generic so that custom types can define formatting rules for themselves. -- Vik Fearing