Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8af310b

Browse files
alvherrejianhe-fun
andcommitted
Prevent creation of duplicate not-null constraints for domains
This was previously harmless, but now that we create pg_constraint rowsfor those, duplicates are not welcome anymore.Backpatch to 18.Co-authored-by: jian he <jian.universality@gmail.com>Co-authored-by: Álvaro Herrera <alvherre@kurilemu.de>Discussion:https://postgr.es/m/CACJufxFSC0mcQ82bSk58sO-WJY4P-o4N6RD2M0D=DD_u_6EzdQ@mail.gmail.com
1 parentf0151e2 commit8af310b

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

‎src/backend/commands/typecmds.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,11 +939,19 @@ DefineDomain(ParseState *pstate, CreateDomainStmt *stmt)
939939
break;
940940

941941
caseCONSTR_NOTNULL:
942-
if (nullDefined&& !typNotNull)
942+
if (nullDefined)
943+
{
944+
if (!typNotNull)
945+
ereport(ERROR,
946+
errcode(ERRCODE_SYNTAX_ERROR),
947+
errmsg("conflicting NULL/NOT NULL constraints"),
948+
parser_errposition(pstate,constr->location));
949+
943950
ereport(ERROR,
944-
errcode(ERRCODE_SYNTAX_ERROR),
945-
errmsg("conflicting NULL/NOT NULLconstraints"),
951+
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
952+
errmsg("redundantNOT NULLconstraint definition"),
946953
parser_errposition(pstate,constr->location));
954+
}
947955
if (constr->is_no_inherit)
948956
ereport(ERROR,
949957
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),

‎src/test/regress/expected/domain.out‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,11 @@ insert into domain_test values (1, 2);
10191019
-- should fail
10201020
alter table domain_test add column c str_domain;
10211021
ERROR: domain str_domain does not allow null values
1022+
-- disallow duplicated not-null constraints
1023+
create domain int_domain1 as int constraint nn1 not null constraint nn2 not null;
1024+
ERROR: redundant NOT NULL constraint definition
1025+
LINE 1: ...domain int_domain1 as int constraint nn1 not null constraint...
1026+
^
10221027
create domain str_domain2 as text check (value <> 'foo') default 'foo';
10231028
-- should fail
10241029
alter table domain_test add column d str_domain2;

‎src/test/regress/sql/domain.sql‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ insert into domain_test values (1, 2);
602602
-- should fail
603603
altertable domain_test add column c str_domain;
604604

605+
-- disallow duplicated not-null constraints
606+
createdomainint_domain1asintconstraint nn1not nullconstraint nn2not null;
607+
605608
createdomainstr_domain2astextcheck (value<>'foo') default'foo';
606609

607610
-- should fail

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp