Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
9ee48915
Commit
9ee48915
authored
Dec 09, 2002
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some quick fixes for ALTER DOMAIN patch. It still needs a lot of work,
but at least it doesn't generate gcc warnings.
parent
4ed6be54
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
96 deletions
+76
-96
src/backend/commands/typecmds.c
src/backend/commands/typecmds.c
+76
-96
No files found.
src/backend/commands/typecmds.c
View file @
9ee48915
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.2
0 2002/12/06 05:00:11 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.2
1 2002/12/09 20:31:05 tgl
Exp $
*
*
* DESCRIPTION
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
* The "DefineFoo" routines take the parse tree and pick out the
...
@@ -63,7 +63,6 @@
...
@@ -63,7 +63,6 @@
static
Oid
findTypeIOFunction
(
List
*
procname
,
Oid
typeOid
,
bool
isOutput
);
static
Oid
findTypeIOFunction
(
List
*
procname
,
Oid
typeOid
,
bool
isOutput
);
static
List
*
get_rels_with_domain
(
Oid
domainOid
);
static
List
*
get_rels_with_domain
(
Oid
domainOid
);
static
void
domainPermissionCheck
(
HeapTuple
tup
,
TypeName
*
typename
);
static
void
domainPermissionCheck
(
HeapTuple
tup
,
TypeName
*
typename
);
static
void
domainCheckForUnsupportedConstraints
(
Node
*
newConstraint
);
static
char
*
domainAddConstraint
(
Oid
domainOid
,
Oid
domainNamespace
,
static
char
*
domainAddConstraint
(
Oid
domainOid
,
Oid
domainNamespace
,
Oid
baseTypeOid
,
Oid
baseTypeOid
,
int
typMod
,
Constraint
*
constr
,
int
typMod
,
Constraint
*
constr
,
...
@@ -519,24 +518,23 @@ DefineDomain(CreateDomainStmt *stmt)
...
@@ -519,24 +518,23 @@ DefineDomain(CreateDomainStmt *stmt)
Constraint
*
colDef
;
Constraint
*
colDef
;
ParseState
*
pstate
;
ParseState
*
pstate
;
/*
/* Check for unsupported constraint types */
* Check for constraint types which are not supported by
if
(
IsA
(
newConstraint
,
FkConstraint
))
* domains. Throws an error if it finds one.
elog
(
ERROR
,
"CREATE DOMAIN / FOREIGN KEY constraints not supported"
);
*/
domainCheckForUnsupportedConstraints
(
newConstraint
);
/* this case should not happen */
if
(
!
IsA
(
newConstraint
,
Constraint
))
elog
(
ERROR
,
"DefineDomain: unexpected constraint node type"
);
/* Assume its a CHECK, DEFAULT, NULL or NOT NULL constraint */
colDef
=
(
Constraint
*
)
newConstraint
;
colDef
=
(
Constraint
*
)
newConstraint
;
switch
(
colDef
->
contype
)
switch
(
colDef
->
contype
)
{
{
case
CONSTR_DEFAULT
:
/*
/*
* The inherited default value may be overridden by the
* The inherited default value may be overridden by the
* user with the DEFAULT <expr> statement.
* user with the DEFAULT <expr> statement.
*
* We have to search the entire constraint tree returned as
* we don't want to cook or fiddle too much.
*/
*/
case
CONSTR_DEFAULT
:
if
(
defaultExpr
)
if
(
defaultExpr
)
elog
(
ERROR
,
"CREATE DOMAIN has multiple DEFAULT expressions"
);
elog
(
ERROR
,
"CREATE DOMAIN has multiple DEFAULT expressions"
);
/* Create a dummy ParseState for transformExpr */
/* Create a dummy ParseState for transformExpr */
...
@@ -563,9 +561,6 @@ DefineDomain(CreateDomainStmt *stmt)
...
@@ -563,9 +561,6 @@ DefineDomain(CreateDomainStmt *stmt)
defaultValueBin
=
nodeToString
(
defaultExpr
);
defaultValueBin
=
nodeToString
(
defaultExpr
);
break
;
break
;
/*
* Find the NULL constraint.
*/
case
CONSTR_NOTNULL
:
case
CONSTR_NOTNULL
:
if
(
nullDefined
)
if
(
nullDefined
)
elog
(
ERROR
,
"CREATE DOMAIN has conflicting NULL / NOT NULL constraint"
);
elog
(
ERROR
,
"CREATE DOMAIN has conflicting NULL / NOT NULL constraint"
);
...
@@ -580,19 +575,34 @@ DefineDomain(CreateDomainStmt *stmt)
...
@@ -580,19 +575,34 @@ DefineDomain(CreateDomainStmt *stmt)
nullDefined
=
true
;
nullDefined
=
true
;
break
;
break
;
case
CONSTR_CHECK
:
/*
/*
* Check constraints are handled after domain creation, as they require
* Check constraints are handled after domain creation, as they
*
the Oid of the domain
* require
the Oid of the domain
*/
*/
case
CONSTR_CHECK
:
break
;
break
;
/*
/*
* If we reach this, then domainCheckForUnsupportedConstraints()
* All else are error cases
* doesn't have a complete list of unsupported domain constraints
*/
*/
case
CONSTR_UNIQUE
:
elog
(
ERROR
,
"CREATE DOMAIN / UNIQUE not supported"
);
break
;
case
CONSTR_PRIMARY
:
elog
(
ERROR
,
"CREATE DOMAIN / PRIMARY KEY not supported"
);
break
;
case
CONSTR_ATTR_DEFERRABLE
:
case
CONSTR_ATTR_NOT_DEFERRABLE
:
case
CONSTR_ATTR_DEFERRED
:
case
CONSTR_ATTR_IMMEDIATE
:
elog
(
ERROR
,
"CREATE DOMAIN: DEFERRABLE, NON DEFERRABLE, DEFERRED"
" and IMMEDIATE not supported"
);
break
;
default:
default:
elog
(
ERROR
,
"DefineDomain: unrecognized constraint
node
type"
);
elog
(
ERROR
,
"DefineDomain: unrecognized constraint
sub
type"
);
break
;
break
;
}
}
}
}
...
@@ -629,6 +639,8 @@ DefineDomain(CreateDomainStmt *stmt)
...
@@ -629,6 +639,8 @@ DefineDomain(CreateDomainStmt *stmt)
{
{
Constraint
*
constr
=
lfirst
(
listptr
);
Constraint
*
constr
=
lfirst
(
listptr
);
/* it must be a Constraint, per check above */
switch
(
constr
->
contype
)
switch
(
constr
->
contype
)
{
{
case
CONSTR_CHECK
:
case
CONSTR_CHECK
:
...
@@ -642,7 +654,8 @@ DefineDomain(CreateDomainStmt *stmt)
...
@@ -642,7 +654,8 @@ DefineDomain(CreateDomainStmt *stmt)
}
}
break
;
break
;
/* Errors for other constraints are taken care of prior to domain creation */
/* Other constraint types were fully processed above */
default:
default:
break
;
break
;
}
}
...
@@ -1262,21 +1275,21 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
...
@@ -1262,21 +1275,21 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
elog
(
ERROR
,
"AlterDomain: type
\"
%s
\"
does not exist"
,
elog
(
ERROR
,
"AlterDomain: type
\"
%s
\"
does not exist"
,
TypeNameToString
(
typename
));
TypeNameToString
(
typename
));
typTup
=
(
Form_pg_type
)
GETSTRUCT
(
tup
);
/* Doesn't return if user isn't allowed to alter the domain */
/* Doesn't return if user isn't allowed to alter the domain */
domainPermissionCheck
(
tup
,
typename
);
domainPermissionCheck
(
tup
,
typename
);
typTup
=
(
Form_pg_type
)
GETSTRUCT
(
tup
);
/* Check for unsupported constraint types */
if
(
IsA
(
newConstraint
,
FkConstraint
))
elog
(
ERROR
,
"ALTER DOMAIN / FOREIGN KEY constraints not supported"
);
/*
/* this case should not happen */
* Check for constraint types which are not supported by
if
(
!
IsA
(
newConstraint
,
Constraint
))
* domains. Throws an error if it finds one.
elog
(
ERROR
,
"AlterDomainAddConstraint: unexpected constraint node type"
);
*/
domainCheckForUnsupportedConstraints
(
newConstraint
);
/* Assume its a CHECK, DEFAULT, NULL or NOT NULL constraint */
constr
=
(
Constraint
*
)
newConstraint
;
constr
=
(
Constraint
*
)
newConstraint
;
switch
(
constr
->
contype
)
switch
(
constr
->
contype
)
{
{
case
CONSTR_DEFAULT
:
case
CONSTR_DEFAULT
:
...
@@ -1288,32 +1301,42 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
...
@@ -1288,32 +1301,42 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
elog
(
ERROR
,
"Use ALTER DOMAIN .. [ SET | DROP ] NOT NULL instead"
);
elog
(
ERROR
,
"Use ALTER DOMAIN .. [ SET | DROP ] NOT NULL instead"
);
break
;
break
;
/*
* Check constraints are handled after domain creation, as they require
* the Oid of the domain
*/
case
CONSTR_CHECK
:
case
CONSTR_CHECK
:
{
/* processed below */
/* Returns the cooked constraint which is not needed during creation */
break
;
ccbin
=
domainAddConstraint
(
HeapTupleGetOid
(
tup
),
typTup
->
typnamespace
,
typTup
->
typbasetype
,
typTup
->
typtypmod
,
case
CONSTR_UNIQUE
:
constr
,
&
counter
,
NameStr
(
typTup
->
typname
));
elog
(
ERROR
,
"ALTER DOMAIN / UNIQUE indexes not supported"
);
}
break
;
case
CONSTR_PRIMARY
:
elog
(
ERROR
,
"ALTER DOMAIN / PRIMARY KEY indexes not supported"
);
break
;
case
CONSTR_ATTR_DEFERRABLE
:
case
CONSTR_ATTR_NOT_DEFERRABLE
:
case
CONSTR_ATTR_DEFERRED
:
case
CONSTR_ATTR_IMMEDIATE
:
elog
(
ERROR
,
"ALTER DOMAIN: DEFERRABLE, NON DEFERRABLE, DEFERRED"
" and IMMEDIATE not supported"
);
break
;
break
;
/*
* If we reach this, then domainCheckForUnsupportedConstraints()
* doesn't have a complete list of unsupported domain constraints
*/
default:
default:
elog
(
ERROR
,
"
DefineDomain
: unrecognized constraint node type"
);
elog
(
ERROR
,
"
AlterDomainAddConstraint
: unrecognized constraint node type"
);
break
;
break
;
}
}
/*
/*
* Since all other constraint types throw errors, this must be
* Since all other constraint types throw errors, this must be
* a check constraint, and ccbin must be set.
* a check constraint.
*
*/
/* Returns the cooked constraint which is not needed during creation */
ccbin
=
domainAddConstraint
(
HeapTupleGetOid
(
tup
),
typTup
->
typnamespace
,
typTup
->
typbasetype
,
typTup
->
typtypmod
,
constr
,
&
counter
,
NameStr
(
typTup
->
typname
));
/*
* Test all values stored in the attributes based on the domain
* Test all values stored in the attributes based on the domain
* the constraint is being added to.
* the constraint is being added to.
*/
*/
...
@@ -1424,7 +1447,7 @@ get_rels_with_domain(Oid domainOid)
...
@@ -1424,7 +1447,7 @@ get_rels_with_domain(Oid domainOid)
/* Scan through pg_class for tables */
/* Scan through pg_class for tables */
while
((
classTup
=
heap_getnext
(
classScan
,
ForwardScanDirection
))
!=
NULL
)
while
((
classTup
=
heap_getnext
(
classScan
,
ForwardScanDirection
))
!=
NULL
)
{
{
bool
addToList
=
true
;
relToCheck
*
rtc
=
NULL
;
int
nkeys
=
0
;
int
nkeys
=
0
;
HeapTuple
attTup
;
HeapTuple
attTup
;
HeapScanDesc
attScan
;
HeapScanDesc
attScan
;
...
@@ -1447,13 +1470,9 @@ get_rels_with_domain(Oid domainOid)
...
@@ -1447,13 +1470,9 @@ get_rels_with_domain(Oid domainOid)
/* Scan through pg_attribute for attributes based on the domain */
/* Scan through pg_attribute for attributes based on the domain */
while
((
attTup
=
heap_getnext
(
attScan
,
ForwardScanDirection
))
!=
NULL
)
while
((
attTup
=
heap_getnext
(
attScan
,
ForwardScanDirection
))
!=
NULL
)
{
{
relToCheck
*
rtc
;
if
(
rtc
==
NULL
)
/* Make the list entries for the relation */
if
(
addToList
)
{
{
addToList
=
false
;
/* First one found for this rel */
rtc
=
(
relToCheck
*
)
palloc
(
sizeof
(
relToCheck
));
rtc
=
(
relToCheck
*
)
palloc
(
sizeof
(
relToCheck
));
rtc
->
atts
=
(
int
*
)
palloc
(
sizeof
(
int
)
*
pg_class
->
relnatts
);
rtc
->
atts
=
(
int
*
)
palloc
(
sizeof
(
int
)
*
pg_class
->
relnatts
);
rtc
->
relOid
=
HeapTupleGetOid
(
classTup
);
rtc
->
relOid
=
HeapTupleGetOid
(
classTup
);
...
@@ -1625,42 +1644,3 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
...
@@ -1625,42 +1644,3 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
*/
*/
return
ccbin
;
return
ccbin
;
}
}
/*
* domainCheckForUnsupportedConstraints
*
* Throws an error on constraints that are unsupported by the
* domains.
*/
void
domainCheckForUnsupportedConstraints
(
Node
*
newConstraint
)
{
Constraint
*
colDef
;
if
(
nodeTag
(
newConstraint
)
==
T_FkConstraint
)
elog
(
ERROR
,
"CREATE DOMAIN / FOREIGN KEY constraints not supported"
);
colDef
=
(
Constraint
*
)
newConstraint
;
switch
(
colDef
->
contype
)
{
case
CONSTR_UNIQUE
:
elog
(
ERROR
,
"CREATE DOMAIN / UNIQUE indexes not supported"
);
break
;
case
CONSTR_PRIMARY
:
elog
(
ERROR
,
"CREATE DOMAIN / PRIMARY KEY indexes not supported"
);
break
;
case
CONSTR_ATTR_DEFERRABLE
:
case
CONSTR_ATTR_NOT_DEFERRABLE
:
case
CONSTR_ATTR_DEFERRED
:
case
CONSTR_ATTR_IMMEDIATE
:
elog
(
ERROR
,
"DefineDomain: DEFERRABLE, NON DEFERRABLE, DEFERRED"
" and IMMEDIATE not supported"
);
break
;
default:
break
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment