aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2024-04-15 08:20:34 +0200
committerPeter Eisentraut <peter@eisentraut.org>2024-04-15 08:34:45 +0200
commit9895b35cb88edc30b836661dbc26d7665716b5a0 (patch)
tree951ebe60a7af44a3e5246b323459c84e19f9b2d7 /doc/src
parentd21d61b96f7a4d89e4b2e7cc9b9a1ec3f642fa12 (diff)
downloadpostgresql-9895b35cb88edc30b836661dbc26d7665716b5a0.tar.gz
postgresql-9895b35cb88edc30b836661dbc26d7665716b5a0.zip
Fix ALTER DOMAIN NOT NULL syntax
This addresses a few problems with commit e5da0fe3c22 ("Catalog domain not-null constraints"). In CREATE DOMAIN, a NOT NULL constraint looks like CREATE DOMAIN d1 AS int [ CONSTRAINT conname ] NOT NULL (Before e5da0fe3c22, the constraint name was accepted but ignored.) But in ALTER DOMAIN, a NOT NULL constraint looks like ALTER DOMAIN d1 ADD [ CONSTRAINT conname ] NOT NULL VALUE where VALUE is where for a table constraint the column name would be. (This works as of e5da0fe3c22. Before e5da0fe3c22, this syntax resulted in an internal error.) But for domains, this latter syntax is confusing and needlessly inconsistent between CREATE and ALTER. So this changes it to just ALTER DOMAIN d1 ADD [ CONSTRAINT conname ] NOT NULL (None of these syntaxes are per SQL standard; we are just living with the bits of inconsistency that have built up over time.) In passing, this also changes the psql \dD output to not show not-null constraints in the column "Check", since it's already shown in the column "Nullable". This has also been off since e5da0fe3c22. Reviewed-by: jian he <jian.universality@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/9ec24d7b-633d-463a-84c6-7acff769c9e8%40eisentraut.org
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ref/create_domain.sgml17
1 files changed, 14 insertions, 3 deletions
diff --git a/doc/src/sgml/ref/create_domain.sgml b/doc/src/sgml/ref/create_domain.sgml
index 73f9f28d6cf..ce555203486 100644
--- a/doc/src/sgml/ref/create_domain.sgml
+++ b/doc/src/sgml/ref/create_domain.sgml
@@ -24,9 +24,9 @@ PostgreSQL documentation
CREATE DOMAIN <replaceable class="parameter">name</replaceable> [ AS ] <replaceable class="parameter">data_type</replaceable>
[ COLLATE <replaceable>collation</replaceable> ]
[ DEFAULT <replaceable>expression</replaceable> ]
- [ <replaceable class="parameter">constraint</replaceable> [ ... ] ]
+ [ <replaceable class="parameter">domain_constraint</replaceable> [ ... ] ]
-<phrase>where <replaceable class="parameter">constraint</replaceable> is:</phrase>
+<phrase>where <replaceable class="parameter">domain_constraint</replaceable> is:</phrase>
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ]
{ NOT NULL | NULL | CHECK (<replaceable class="parameter">expression</replaceable>) }
@@ -190,7 +190,7 @@ CREATE DOMAIN <replaceable class="parameter">name</replaceable> [ AS ] <replacea
</variablelist>
</refsect1>
- <refsect1>
+ <refsect1 id="sql-createdomain-notes">
<title>Notes</title>
<para>
@@ -279,6 +279,17 @@ CREATE TABLE us_snail_addy (
The command <command>CREATE DOMAIN</command> conforms to the SQL
standard.
</para>
+
+ <para>
+ The syntax <literal>NOT NULL</literal> in this command is a
+ <productname>PostgreSQL</productname> extension. (A standard-conforming
+ way to write the same would be <literal>CHECK (VALUE IS NOT
+ NULL)</literal>. However, per <xref linkend="sql-createdomain-notes"/>,
+ such constraints are best avoided in practice anyway.) The
+ <literal>NULL</literal> <quote>constraint</quote> is a
+ <productname>PostgreSQL</productname> extension (see also <xref
+ linkend="sql-createtable-compatibility"/>).
+ </para>
</refsect1>
<refsect1 id="sql-createdomain-see-also">