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 1uMpuf-0050Oi-81 for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Jun 2025 15:20:21 +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 1uMpud-00DYDd-B8 for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Jun 2025 15:20:19 +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 1uMpuc-00DYDJ-Sb for pgsql-hackers@lists.postgresql.org; Wed, 04 Jun 2025 15:20:19 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uMpua-000Bnh-2R for pgsql-hackers@lists.postgresql.org; Wed, 04 Jun 2025 15:20:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1749050111; bh=t7ICjIemfOAnV/AI+kBtWg8BolLSigdMXzev0RuFSoc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID:From; b=ohXTDOpevBqzfueL8XMfgM4RLmCMMPpwFU2LpaFwqXMr6qHOhqcksUqU6Vsj6DcoS uOm1f96CtjBhFWOwmYey6+xVQux4q/bDJuu9ydJ9g9CD/o/0OZ+gQaSmm/Q4iGeLLd BCAWuP7vdFKDealD/i5sVcNvZ0HVHOBsoYFIGxPY7igYYRAuCf8FLWNUmeICf/NQYt dXNtnDuqxmIxbZ9+E0nO33MfC01L3rU5Nn7Icka7CvBrS2OeqLjQab7LYyNQHZDqdr oo1DSQxxwd/q/Y7YDHzJEZVBhcKO1sQfXRJ51Jbk6BWuTfdpWTtfGPEz3hq3UgBugU zDQSyO/fxTXJw== Received: from mail.postgrespro.ru (webmail-slave-mstn.l.postgrespro.ru [192.168.2.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.pyhalov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id A21DD60A9A; Wed, 4 Jun 2025 18:15:11 +0300 (MSK) MIME-Version: 1.0 Date: Wed, 04 Jun 2025 18:15:11 +0300 From: Alexander Pyhalov To: Alexander Korotkov Cc: Maxim Orlov , pgsql-hackers@lists.postgresql.org Subject: Re: postgres_fdw could deparse ArrayCoerceExpr In-Reply-To: References: <4f0cea802476d23c6e799512ffd17aff@postgrespro.ru> <0be55d1548c3b1bc29b8ae23f6db24e3@postgrespro.ru> Message-ID: X-Sender: a.pyhalov@postgrespro.ru Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/06/04 12:53:00 #27536686 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi. Alexander Korotkov писал(а) 2025-06-04 14:29: > On Wed, Jan 29, 2025 at 11:59 AM Maxim Orlov wrote: >> >> One important note here. This patch will change cast behaviour in case >> of local and foreign types are mismatched. >> The problem is if we cannot convert types locally, this does not mean >> that it is also true for a foreign wrapped data. >> In any case, it's up to the committer to decide whether this change is >> needed or not. > > I have two question regarding this aspect. > 1) Is it the same with regular type conversion? Yes, it's the same. CREATE TYPE enum_of_int_like AS enum('1', '2', '3', '4'); CREATE TABLE conversions(id int, d enum_of_int_like); CREATE FOREIGN TABLE ft_conversions (id int, d char(1)) SERVER loopback options (table_name 'conversions'); SET plan_cache_mode = force_generic_plan; PREPARE s(varchar) AS SELECT count(*) FROM ft_conversions where d=$1; EXPLAIN (VERBOSE, COSTS OFF) EXECUTE s('1'); QUERY PLAN ------------------------------------------------------------------------------------------- Foreign Scan Output: (count(*)) Relations: Aggregate on (public.ft_conversions) Remote SQL: SELECT count(*) FROM public.conversions WHERE ((d = $1::character varying)) (4 rows) EXECUTE s('1'); ERROR: operator does not exist: public.enum_of_int_like = character varying HINT: No operator matches the given name and argument types. You might need to add explicit type casts. > 2) Can we fallback to remote type conversion in local type conversion > fails? It's the opposite - we've already planned (and deparsed) statement, using remote type conversion. When plan execution fails, there's nothing we can do. We'll get PREPARE s(varchar[]) AS SELECT count(*) FROM ft_conversions where d=ANY($1); EXPLAIN (VERBOSE, COSTS OFF) EXECUTE s(ARRAY['1','2']); QUERY PLAN --------------------------------------------------------------------------------------------------- Foreign Scan Output: (count(*)) Relations: Aggregate on (public.ft_conversions) Remote SQL: SELECT count(*) FROM public.conversions WHERE ((d = ANY ($1::character varying[]))) (4 rows) EXECUTE s(ARRAY['1','2']); ERROR: operator does not exist: public.enum_of_int_like = character varying HINT: No operator matches the given name and argument types. You might need to add explicit type casts. -- Best regards, Alexander Pyhalov, Postgres Professional