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.96) (envelope-from ) id 1wfPpC-005RAQ-0g for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jul 2026 22:24:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wfPpA-003eIS-2v for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jul 2026 22:24:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wfPpA-003eIK-1u for pgsql-hackers@lists.postgresql.org; Thu, 02 Jul 2026 22:24:00 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wfPp7-00000001PCx-45I5 for pgsql-hackers@postgresql.org; Thu, 02 Jul 2026 22:23:59 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-c1268d56234so328867066b.2 for ; Thu, 02 Jul 2026 15:23:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783031037; cv=none; d=google.com; s=arc-20260327; b=WksAE2dXhl0xAJrMAXeIyblWvwKiON434/UF7nCzey0oKeBDyShApGNjH6Dv1o+qSS myUVr1dnKEh+P5bhl9vMtRwRmsVp+HcbiJLe+FLEHlxysNzvjmfPR4naC0WUcvpfyYnS WpKK0Wq3b8l9aLnPlcpCwU1JNkXnUFieLNTU3tb+Nof8OQ7l+9tz3SZMVktIEaPQ3KLn sP7+YT0H0B/INn8Ht1JKUDuuyk5tKo/WJ+68iszUTvnBK26EL52Q0N7YIF+fqmXUksjW ZIWvzkKYX44ovsnVDfHTF4Plgj+5t2+bYE51s6c0sRR5UgpOnm3EVoFVRwwTEh6ChgAn R+3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=XsLV/lJoC/Cknr/53Sp7ss/0X75foP4B9H75+RPV2U4=; fh=2w/nM5pv8FMBjccpll+ZoYuDrf4IwnqswQobth6RUk0=; b=nlD9SDkAokb5z91Rsz1zfnulCScSmfOAmz0Koyj0xWQca4XqEElMbC1kEfZRvW6R8N 0I8mSXqDI9LMb96sLj93RXQdsM5ju/WK5qVlVqbea8NOQ7ae3EwQdmU8o+C26VsJahho yEztXTaaJJNxFIC8b3R9/MH/JIOQaEeW0fht06Y620lM6zLSCU2dlzBVsis7t4f5PKRf 6XCBPj5hjzSuUuIKrpFO5Nek/6Rq0/6VJkw1/1v2YS2kxLlYeszV0Zk5pda+g3vINdWM aKnr1U0XxTY/3rNC+Ajz5syqa9oRn5rxHPv0yc0iPwb7BAEc+8vjl3zuB8FnasrUoaYZ +J4w==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783031037; x=1783635837; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=XsLV/lJoC/Cknr/53Sp7ss/0X75foP4B9H75+RPV2U4=; b=B1Pl2nEvzYSQ7/pSKl0Hhk0IaoE0alH3g+qaZ364cXf7ov0HtslZPDcBMipEPrCzTd 8pPjZWCkWojTuRsaDj6/RUo83hedIuvZyDQWYOj2LwYIWtfL0XWIu+l0+5cn6zvRudel VmCLX+BQctAWFxPBOOiBI5D+FqUwSTXzZgwujkGd+qRGZswxFvbTnNwGPFqWuIdIszfx 4zfm4/R5Q62BAhTalAm8dJz5cxJVFuyTiPy95S97WzJiKv/Qj19wKhT85osklJw7BdDv Vptt4H38VyOo/pYlGNsOWzw73bT4JtzKAyRBkMcVzDKp3yYyA9WM7h60Zgk/a6Tb/cpM f44A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783031037; x=1783635837; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=XsLV/lJoC/Cknr/53Sp7ss/0X75foP4B9H75+RPV2U4=; b=F1VdjPXZGmQ/1ioF11qL2QwpdwlnglYfPcgna5s1TvPYSFlfsWMOhLAFu2VAc2MJzs G7gVMuObu3q2PB96cVnX5zEb2TK2UoBq5bdmJFWCWOZWrBMmq+qtGSRlEC9vIELQoTZs sdqm8e6A6mM5gJfMm0BxMpkg+hJEDm+rvGmkf3KT+ElhgPOeSyGXV8agaRaxDm8O6q9N /v2HOfSkfnp8owrjDY3FwU1eL0/zUZbKgi1qUQMY2M/JANAebK+QdDqWE25yVyYScTLe 1O74SC+czu8drBu+rScB9nhN2tJ0iZNIXF2yGTej75QWaU5GQwhecXHxzowJYeQdUA47 zziQ== X-Forwarded-Encrypted: i=1; AFNElJ+RSJZgIT8RVYxehX7hlo0MocOW23gaj2VmpwD6V6VPgzRqQc49lGi6jPffixIQtDoK+KCCz+6tUQvokVUi@postgresql.org X-Gm-Message-State: AOJu0YxUALMKpQGn3fryScB5LWz/G/N1riqL1w5qSH0BCrsJMOYN8sq7 fQVw9WP4pfCXqimPyONwgrBuFl8E1d+lXDTmQCfybSpar8HcH13Z7P1sTXPEy9Xdd8f+rWK3CK+ zWdoGmiJ/khTwIZcbhSsSdY4295yEHe4= X-Gm-Gg: AfdE7cnFoThvuYVh9BjBk92n4CDosokZl64A5Ou2bFASQIlpBSyoEpINd71G+qeQzc8 XxMU3xKxtHy08sMxWsO4QT9wY5MDE6lD1kTcunPSvcBIBA9tSdB8nsySXf9cU88dzcJrxCaIZ8I n4kpOBPkb4PrLqGXYOvwnhBJ4KCg0/WydXPOHZaTU1EggaBb/XzKTbIKt1xxCA5RY6ZSWXpD0Qh CbvlKGwyQuOxkr2nPbnsFUla89sMWL561QV+gLeUAd3PuHLJWoKzQlZkwqHmwKo9rLveF7z23so VdCRkOgqDFvJ1A+xFb9xfEjQiZSo X-Received: by 2002:a17:906:4703:b0:c12:2be5:73fd with SMTP id a640c23a62f3a-c12a9da27e4mr266658066b.27.1783031036400; Thu, 02 Jul 2026 15:23:56 -0700 (PDT) MIME-Version: 1.0 References: <4c358bf8-87e8-4760-83d5-a6f9fcd88907@postgresfriends.org> <1b702de4-86b0-4144-a2d0-38266296894f@postgresfriends.org> <82b4223e-84d4-432d-8167-dd698ce489f5@postgresfriends.org> In-Reply-To: From: Robert Haas Date: Thu, 2 Jul 2026 18:23:43 -0400 X-Gm-Features: AVVi8CdFv5TEprAMueOSHAgkjfvwInCzSC9ErtsKlZUCOVvVq02nip9Veds-CRg Message-ID: Subject: Re: implement CAST(expr AS type FORMAT 'template') To: "David G. Johnston" Cc: Haibo Yan , jian he , Corey Huinker , Zsolt Parragi , Vik Fearing , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jul 2, 2026 at 5:52=E2=80=AFPM David G. Johnston wrote: > There is no wanting the formatless-variant to fail. There is recognition= that sometime the formatless variant might fail with a syntax error and we= have a way to pass a format to make the cast work. > > If there is no cast from thistype to thattype both will fail with cast no= t found errors. Once a cast exists the first one could pass or fail depend= ing on the content being casted. If the content has an internal structure/= syntax the failure mode would then be a syntax error. Overcoming a syntax = error is done by specifying a format. But a format does you no good if the= re isn=E2=80=99t some cast pathway already available to use it. IOW a form= at should never be required - some default exists, like for dates today, th= at allows the non-format cast to work. We just need some way to pass in a = format to that cast function if one is specified. > > For me the presence of the word cast in the syntax drives this way of thi= nking about the problem/design. I=E2=80=99d rather just stick with our pol= ymorphic to_char functions if we want some way of outputting text with a fo= rmat at without having to call doing so a cast. I don't really know how to have a productive conversation about this at this point. I agree that we might be better off just sticking with our polymorphic to_char functions. But if we want to implement CAST(... FORMAT ...) I do not understand how what you've written above amounts to a coherent design proposal; it just doesn't make any sense to me. If you spell it out with specific syntax, specific catalog changes, and specific ways that things would work, then maybe I would have an opinion, but right now all I can really say is that I disagree strongly with the idea of trying to treat CAST(a AS b) and CAST(a AS b FORMAT c) as two variants of the same thing just because they both have CAST in the name. It matters whether they actually *do* the same thing -- whether they could reasonably be implemented by the same code -- and I think they can't. --=20 Robert Haas EDB: http://www.enterprisedb.com