Re: PostgreSQL domains and NOT NULL constraint

2023-10-23 Thread Tom Lane
Matthias van de Meent writes: > On Mon, 23 Oct 2023, 19:34 Tom Lane, wrote: >> After ruminating on this for awhile, here's a straw-man proposal: >> ... > How does this work w.r.t. concurrently created tables that contain the > domain? It wouldn't change that at all I think. I had noticed that

Re: PostgreSQL domains and NOT NULL constraint

2023-10-23 Thread Matthias van de Meent
On Mon, 23 Oct 2023, 19:34 Tom Lane, wrote: > > I wrote: > > Given the exception the spec makes for CAST, I wonder if we shouldn't > > just say "NULL is a valid value of every domain type, as well as every > > base type. If you don't like it, too bad; write a separate NOT NULL > > constraint for

Re: PostgreSQL domains and NOT NULL constraint

2023-10-23 Thread Tom Lane
I wrote: > Isaac Morland writes: >> If we decide we do want "CHECK (VALUE NOT NULL)" to work, then I wonder if >> we could pass NULL to the constraint at CREATE DOMAIN time, and if it >> returns FALSE, do exactly what we would have done (set pg_type.typnotnull) >> if an actual NOT NULL clause had

Re: PostgreSQL domains and NOT NULL constraint

2023-10-23 Thread Tom Lane
Isaac Morland writes: > Then domain CHECK constraints are checked anytime a non-NULL value is > turned into a domain value, and NOT NULL ones are checked only when storing > to a table. CHECK constraints would be like STRICT functions; if the input > is NULL, the implementation is not run and the

Re: PostgreSQL domains and NOT NULL constraint

2023-10-23 Thread Tom Lane
Vik Fearing writes: > On 10/23/23 18:53, Tom Lane wrote: >> (1A) It satisfies the plain language of the SQL spec about >> how CAST to a domain type behaves. > I agree with all of your proposal, except for this part. I think the > shortcut in the General Rules of is an oversight > and I plan

Re: PostgreSQL domains and NOT NULL constraint

2023-10-23 Thread Vik Fearing
On 10/23/23 18:53, Tom Lane wrote: 1. Domains are data types, with the proviso that NULL is always a valid value no matter what the domain constraints might say. Implementation-wise, this'd just require that CoerceToDomain immediately return any null input without checking the constraints.

Re: PostgreSQL domains and NOT NULL constraint

2023-10-23 Thread Vik Fearing
On 10/23/23 20:36, Isaac Morland wrote: Also, where it says "Expressions evaluating to TRUE or UNKNOWN succeed": Do we really mean "Expressions evaluating to TRUE or NULL succeed"? No, UNKNOWN is the correct nomenclature for booleans. -- Vik Fearing

Re: PostgreSQL domains and NOT NULL constraint

2023-10-23 Thread Pavel Stehule
po 23. 10. 2023 v 19:34 odesílatel Tom Lane napsal: > I wrote: > > Given the exception the spec makes for CAST, I wonder if we shouldn't > > just say "NULL is a valid value of every domain type, as well as every > > base type. If you don't like it, too bad; write a separate NOT NULL > >

Re: PostgreSQL domains and NOT NULL constraint

2023-10-23 Thread Isaac Morland
On Mon, 23 Oct 2023 at 13:40, Tom Lane wrote: > I wrote: > > Given the exception the spec makes for CAST, I wonder if we shouldn't > > just say "NULL is a valid value of every domain type, as well as every > > base type. If you don't like it, too bad; write a separate NOT NULL > > constraint

Re: PostgreSQL domains and NOT NULL constraint

2023-10-23 Thread Tom Lane
I wrote: > Given the exception the spec makes for CAST, I wonder if we shouldn't > just say "NULL is a valid value of every domain type, as well as every > base type. If you don't like it, too bad; write a separate NOT NULL > constraint for your table column." After ruminating on this for

Re: PostgreSQL domains and NOT NULL constraint

2023-10-15 Thread Erki Eessaar
Eessaar ; pgsql-hackers@lists.postgresql.org Subject: Re: PostgreSQL domains and NOT NULL constraint Vik Fearing writes: > On 10/13/23 06:37, Tom Lane wrote: >> Hmph. The really basic problem here, I think, is that the spec >> wants to claim that a domain is a data type, but then i

Re: PostgreSQL domains and NOT NULL constraint

2023-10-14 Thread Tom Lane
Vik Fearing writes: > On 10/13/23 06:37, Tom Lane wrote: >> Hmph. The really basic problem here, I think, is that the spec >> wants to claim that a domain is a data type, but then it backs >> off and limits where the domain's constraints need to hold. > I don't think that is an accurate

Re: PostgreSQL domains and NOT NULL constraint

2023-10-14 Thread Vik Fearing
On 10/13/23 06:37, Tom Lane wrote: If it's not nominally of a domain type, please cite chapter and verse that says it isn't. Okay, I found it. SQL:2023-2 6.7 Syntax Rules 5) Let C be the column that is referenced by CR. The declared type of CR is Case: a) If the column descriptor of

Re: PostgreSQL domains and NOT NULL constraint

2023-10-14 Thread Erki Eessaar
>I doubt we'd consider doing anything about that. >The whole business of domains with NOT NULL constraints >is arguably a defect of the SQL standard, because >there are multiple ways to produce a value that >is NULL and yet must be considered to be of the domain type. In my opinion it is

Re: PostgreSQL domains and NOT NULL constraint

2023-10-13 Thread Vik Fearing
On 10/13/23 06:37, Tom Lane wrote: Vik Fearing writes: Regardless of what the spec may or may not say about v1.d, it still remains that nulls should not be allowed in a *base table* if the domain says nulls are not allowed. Not mentioned in this thread but the constraints are also applied

Re: PostgreSQL domains and NOT NULL constraint

2023-10-13 Thread Erki Eessaar
, then it would mean that systems actually rely on this constraint. Best regards Erki Eessaar From: Tom Lane Sent: Friday, October 13, 2023 08:37 To: Vik Fearing Cc: Erki Eessaar ; pgsql-hackers@lists.postgresql.org Subject: Re: PostgreSQL domains and NOT NULL constraint

Re: PostgreSQL domains and NOT NULL constraint

2023-10-12 Thread Tom Lane
Vik Fearing writes: > Regardless of what the spec may or may not say about v1.d, it still > remains that nulls should not be allowed in a *base table* if the domain > says nulls are not allowed. Not mentioned in this thread but the > constraints are also applied when CASTing to the domain.

Re: PostgreSQL domains and NOT NULL constraint

2023-10-12 Thread Vik Fearing
On 10/13/23 02:44, Tom Lane wrote: Vik Fearing writes: On 10/12/23 15:54, Tom Lane wrote: There's been some discussion of treating the output of such a join, subselect, etc as being of the domain's base type not the domain proper. That'd solve this particular issue since then we'd decide we

Re: PostgreSQL domains and NOT NULL constraint

2023-10-12 Thread Tom Lane
Vik Fearing writes: > On 10/12/23 15:54, Tom Lane wrote: >> There's been some discussion of treating the output of such a join, >> subselect, etc as being of the domain's base type not the domain >> proper. That'd solve this particular issue since then we'd decide >> we have to cast the base

Re: PostgreSQL domains and NOT NULL constraint

2023-10-12 Thread Vik Fearing
On 10/12/23 15:54, Tom Lane wrote: Erki Eessaar writes: PostgreSQL's CREATE DOMAIN documentation (section Notes) describes a way how one can add NULL's to a column that has a domain with the NOT NULL constraint. https://www.postgresql.org/docs/current/sql-createdomain.html To me it seems very

Re: PostgreSQL domains and NOT NULL constraint

2023-10-12 Thread Tom Lane
Erki Eessaar writes: > PostgreSQL's CREATE DOMAIN documentation (section Notes) describes a way how > one can add NULL's to a column that has a domain with the NOT NULL constraint. > https://www.postgresql.org/docs/current/sql-createdomain.html > To me it seems very strange and amounts to a bug

PostgreSQL domains and NOT NULL constraint

2023-10-12 Thread Erki Eessaar
Hello PostgreSQL's CREATE DOMAIN documentation (section Notes) describes a way how one can add NULL's to a column that has a domain with the NOT NULL constraint. https://www.postgresql.org/docs/current/sql-createdomain.html To me it seems very strange and amounts to a bug because it defeats the