public inbox for [email protected]  
help / color / mirror / Atom feed
From: jian he <[email protected]>
To: Tom Lane <[email protected]>
Cc: Heikki Linnakangas <[email protected]>
Cc: [email protected]
Cc: Chao Li <[email protected]>
Cc: Andrew Dunstan <[email protected]>
Subject: Re: Fix domain fast defaults on empty tables
Date: Mon, 8 Jun 2026 08:33:53 +0800
Message-ID: <CACJufxH+qnnWaySKbJD8pBL5Q+aYFE+hffb6-byT_6uPRB1J2Q@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>

On Fri, Jun 5, 2026 at 10:08 PM Tom Lane <[email protected]> wrote:
>
> Heikki Linnakangas <[email protected]> writes:
> > On 5 June 2026 10:48:00 EEST, Chao Li <[email protected]> wrote:
> >> evantest=# create domain d_div as int check (1 / (value - 1) > 0);
> >> CREATE DOMAIN
> >> evantest=# create table t (a int);
> >> CREATE TABLE
> >> evantest=# alter table t add column b d_div default 1;
> >> ERROR:  division by zero
>
> > It seems totally reasonable to get an error in that case. '1' is not a valid value for the datatype, whether or not there are any rows in the table.
>
> I think there's reason for concern here, which is that we do not throw
> an error for the apparently equivalent case
>
> regression=# create table t2 (a int, b d_div default 1);
> CREATE TABLE
>
> This will give you an error at INSERT, but not CREATE.  So this
> is inconsistent, as well as different from the pre-v19 behavior.
>

However, this is normal behavior for non-domain types.

create table t2 (a numeric default (1::numeric/0.0::float4)); --  ok
alter table t2 add column b numeric default ((1::numeric/0.0::float4)); -- error






view thread (11+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Fix domain fast defaults on empty tables
  In-Reply-To: <CACJufxH+qnnWaySKbJD8pBL5Q+aYFE+hffb6-byT_6uPRB1J2Q@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox