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 1uewFt-00Gv8Z-MC for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jul 2025 13:45:06 +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 1uewFq-00878n-Hj for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jul 2025 13:45:02 +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 1uewFq-00878f-8V for pgsql-hackers@lists.postgresql.org; Thu, 24 Jul 2025 13:45:02 +0000 Received: from mail-vs1-xe2e.google.com ([2607:f8b0:4864:20::e2e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uewFo-000YlJ-2b for pgsql-hackers@lists.postgresql.org; Thu, 24 Jul 2025 13:45:01 +0000 Received: by mail-vs1-xe2e.google.com with SMTP id ada2fe7eead31-4e7fb730078so364945137.1 for ; Thu, 24 Jul 2025 06:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753364700; x=1753969500; darn=lists.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=XxkcD7+wgfzkPggmPKDhla3VqwNjUFBt/2I2tS8ObGg=; b=hKbC28e2LQOJyiSjZEXxkwooAw9+kTFeNVs2aLmaDcxj5p/2Zrf6P3eS5FdDpbESWb ORCcwYoXnF7xaLKWlHrh9Q9VvJgrlwPUxQxnEeia+Jm1/T7vlgoTd3mIs/+OLMt9/NBl zLJsXAL4aMBvMBccb85acRn6XfqrRY+CZIQQZnxz3Zh+4V4enl+83nye5vXKOp8kkAPt Djz8xkRP2wMBqbBJT0eVT9pN3yoGHnt32EpRbt+jL9JRYaQu/R3bH473ZttLOD3SZNRu pAkf8qKO+V/Yf0Id/xbRLd//1sURNE04biAeNLBA+5nTxJCgImE5N1lEo6iNTePKqglZ Rhiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753364700; x=1753969500; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XxkcD7+wgfzkPggmPKDhla3VqwNjUFBt/2I2tS8ObGg=; b=B279ONUE1tdTzAMK+K1JTFJGvJDry9a6L6K3DzJqC6aUDwh3/XOjMvoCZrWQ62YXme xa/BPjvjIVdgMmEJrOG7hrwS/GRxSOx8rOmHKNR8XuGefsPJ1d7RtAq/jkXBZdHIwyJh WSI2Pl0tC20SoEPBrfrZ+HwF5KJppyz4Gjv0xiBtsmLNY1H9cL6BWzCzIZyB7y21vSnN E0Np3YCcuqRGueqstF72Seqfkcklor4lwWYoluZNMCIyoEw5iuuVONtO4kbAucrOSZtR wOUVzF8YPGee08OKHHR6ZceGjvsytYypeCQpmnCWMj++sj0LkziS9OVm5DWnpmbWRfth oipA== X-Forwarded-Encrypted: i=1; AJvYcCXPF/W6Z2tbu31KcI4Ez/1oSh6YBM8RxTW7InAOWS8GDFIE0OOP++PvX80Mkq5yH2PA+ueaP1HWXlOQfiyO@lists.postgresql.org X-Gm-Message-State: AOJu0Yxlm+lL0NaRPwg4uCxW6KmBuU4jxwkt7i3BBeTZuM7/nqqtqZCo TEtBGRjtsXluHuL873s2bXmFuLMvutSuuMsPBIOw3uGBphwpBtFL6kvAPAysHkcq6csBysNaqRA yvqACVYqRlUzMdaPAA/ugz/rBNlvRcp4= X-Gm-Gg: ASbGnctZ9co49W2xgX6FOGpt0AVA1aqYj4i04YwqUYxSLn2gx8D60qnL7suisFoQa4J 8JDpm1odxc/gaZ8Pdtm43H7BOhfm67ZpwUsTzQFGiOgLT8uv4wbBGuZLnL8tw/OfGEMAnR2QAcK 3UFhk29DG6vjruCRXvUz+CBHJq0LYkMBKNkILxAsXwcdfp4PyRRlukNazNLDsiaX7xI1vSqePaE 9hZrfoq0VEWQpNknyNArgXTGHZfskNBdcYk2SE= X-Google-Smtp-Source: AGHT+IEOeSN7wWwNlXHLZ/hfxSo02wZRv5A5xB+ZotK+j2Wyeu85M2DecoERy/DQx/s07IY76Z1z9klBS8zs0+pfqDU= X-Received: by 2002:a05:6102:1612:b0:4e9:8f71:bd6e with SMTP id ada2fe7eead31-4fa14d0678amr3638506137.0.1753364699778; Thu, 24 Jul 2025 06:44:59 -0700 (PDT) MIME-Version: 1.0 References: <04afcd1f-ed7d-4c0a-add1-50e3719ccbf9@postgresfriends.org> <762ae707-7fdc-43d8-a77a-3a10d12ce21d@postgresfriends.org> In-Reply-To: <762ae707-7fdc-43d8-a77a-3a10d12ce21d@postgresfriends.org> From: jian he Date: Thu, 24 Jul 2025 21:44:22 +0800 X-Gm-Features: Ac12FXyvDt9AVVeE9xqvzYwf4fzys_bHnBQWXnKoh-j44inPdwL77yONFaKxEjE Message-ID: Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions To: Vik Fearing Cc: Corey Huinker , Isaac Morland , pgsql-hackers@lists.postgresql.org 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 Tue, Jul 22, 2025 at 8:26=E2=80=AFPM Vik Fearing wrote: > > > On 22/07/2025 12:19, jian he wrote: > > On Tue, Jul 22, 2025 at 2:45=E2=80=AFPM Vik Fearing wrote: > >> It was accepted into the standard after 2023 was released. I am the > >> author of this change in the standard, so feel free to ask me anything > >> you're unsure about. > >> > > is the generally syntax as mentioned in this thread: > > CAST(source_expression AS target_type DEFAULT default_expression ON ERR= OR) > > > > if so, what's the restriction of default_expression? > > > The actual syntax is: > > > ::=3D > CAST > AS > [ FORMAT ] > [ ON CONVERSION ERROR ] > > > "CONVERSION" is probably a noise word, but it is there because A) Oracle > wanted it there, and B) it makes sense because if the behavior> fails, that is still a failure of the entire CAST. > > > The is: > > > ::=3D > ERROR > | NULL > | DEFAULT > > hi. just want to confirm my understanding of ``[ FORMAT ]``. SELECT CAST('2022-13-32' AS DATE FORMAT 'YYYY-MM-DD' DEFAULT NULL ON CONVERSION ERROR); will return NULL. because ``SELECT to_date('2022-13-32', 'YYYY-MM-DD');`` will error out, so the above query will fall back to the DEFAULT expression evaluation.