aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/gram.y66
-rw-r--r--src/backend/parser/keywords.c3
-rw-r--r--src/backend/parser/parse_coerce.c32
-rw-r--r--src/backend/parser/parse_expr.c7
4 files changed, 97 insertions, 11 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index a8aba404e76..c1b46650917 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.285 2002/03/06 06:09:53 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.286 2002/03/06 20:34:49 momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -135,7 +135,8 @@ static void doNegateFloat(Value *v);
ClosePortalStmt, ClusterStmt, CommentStmt, ConstraintsSetStmt,
CopyStmt, CreateAsStmt, CreateGroupStmt, CreatePLangStmt,
CreateSchemaStmt, CreateSeqStmt, CreateStmt, CreateTrigStmt,
- CreateUserStmt, CreatedbStmt, CursorStmt, DefineStmt, DeleteStmt,
+ CreateUserStmt, CreateDomainStmt, CreatedbStmt, CursorStmt,
+ DefineStmt, DeleteStmt,
DropGroupStmt, DropPLangStmt, DropSchemaStmt, DropStmt, DropTrigStmt,
DropUserStmt, DropdbStmt, ExplainStmt, FetchStmt,
GrantStmt, IndexStmt, InsertStmt, ListenStmt, LoadStmt, LockStmt,
@@ -289,6 +290,8 @@ static void doNegateFloat(Value *v);
%type <list> constraints_set_namelist
%type <boolean> constraints_set_mode
+%type <boolean> opt_as
+
/*
* If you make any token changes, remember to:
* - use "yacc -d" and update parse.h
@@ -343,7 +346,7 @@ static void doNegateFloat(Value *v);
WITHOUT
/* Keywords (in SQL92 non-reserved words) */
-%token COMMITTED, SERIALIZABLE, TYPE_P
+%token COMMITTED, SERIALIZABLE, TYPE_P, DOMAIN_P
/* Keywords for Postgres support (not in SQL92 reserved words)
*
@@ -446,6 +449,7 @@ stmt : AlterDatabaseSetStmt
| CopyStmt
| CreateStmt
| CreateAsStmt
+ | CreateDomainStmt
| CreateSchemaStmt
| CreateGroupStmt
| CreateSeqStmt
@@ -776,7 +780,10 @@ DropSchemaStmt: DROP SCHEMA UserId
n->dbname = $3;
$$ = (Node *)n;
}
+ ;
+
+
/*****************************************************************************
*
@@ -1461,7 +1468,10 @@ ColConstraintElem:
n->name = NULL;
if (exprIsNullConstant($2))
{
- /* DEFAULT NULL should be reported as empty expr */
+ /*
+ * DEFAULT NULL should be reported as empty expr
+ * Required for NOT NULL Domain overrides
+ */
n->raw_expr = NULL;
}
else
@@ -2043,7 +2053,16 @@ def_list: def_elem { $$ = makeList1($1); }
| def_list ',' def_elem { $$ = lappend($1, $3); }
;
-def_elem: ColLabel '=' def_arg
+def_elem: DEFAULT '=' b_expr
+ {
+ $$ = makeNode(DefElem);
+ $$->defname = "default";
+ if (exprIsNullConstant($3))
+ $$->arg = (Node *)NULL;
+ else
+ $$->arg = $3;
+ }
+ | ColLabel '=' def_arg
{
$$ = makeNode(DefElem);
$$->defname = $1;
@@ -2078,6 +2097,15 @@ DropStmt: DROP drop_type name_list
DropStmt *n = makeNode(DropStmt);
n->removeType = $2;
n->names = $3;
+ n->behavior = RESTRICT; /* Restricted by default */
+ $$ = (Node *)n;
+ }
+ | DROP DOMAIN_P name_list drop_behavior
+ {
+ DropStmt *n = makeNode(DropStmt);
+ n->removeType = DROP_DOMAIN_P;
+ n->names = $3;
+ n->behavior = $4;
$$ = (Node *)n;
}
;
@@ -2110,7 +2138,7 @@ TruncateStmt: TRUNCATE opt_table relation_name
* The COMMENT ON statement can take different forms based upon the type of
* the object associated with the comment. The form of the statement is:
*
- * COMMENT ON [ [ DATABASE | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ]
+ * COMMENT ON [ [ DATABASE | DOMAIN | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ]
* <objname> | AGGREGATE <aggname> (<aggtype>) | FUNCTION
* <funcname> (arg1, arg2, ...) | OPERATOR <op>
* (leftoperand_typ rightoperand_typ) | TRIGGER <triggername> ON
@@ -2196,6 +2224,7 @@ comment_type: DATABASE { $$ = DATABASE; }
| RULE { $$ = RULE; }
| SEQUENCE { $$ = SEQUENCE; }
| TABLE { $$ = TABLE; }
+ | DOMAIN_P { $$ = TYPE_P; }
| TYPE_P { $$ = TYPE_P; }
| VIEW { $$ = VIEW; }
;
@@ -3222,6 +3251,30 @@ AlterDatabaseSetStmt: ALTER DATABASE database_name VariableSetStmt
}
;
+/*****************************************************************************
+ *
+ * Manipulate a domain
+ *
+ *
+ *****************************************************************************/
+
+CreateDomainStmt: CREATE DOMAIN_P name opt_as Typename ColQualList opt_collate
+ {
+ CreateDomainStmt *n = makeNode(CreateDomainStmt);
+ n->domainname = $3;
+ n->typename = $5;
+ n->constraints = $6;
+
+ if ($7 != NULL)
+ elog(NOTICE,"CREATE DOMAIN / COLLATE %s not yet "
+ "implemented; clause ignored", $7);
+ $$ = (Node *)n;
+ }
+ ;
+
+opt_as: AS {$$ = TRUE; }
+ | /* EMPTY */ {$$ = FALSE; }
+ ;
/*****************************************************************************
*
@@ -5879,6 +5932,7 @@ unreserved_keyword:
| DEFERRED { $$ = "deferred"; }
| DELETE { $$ = "delete"; }
| DELIMITERS { $$ = "delimiters"; }
+ | DOMAIN_P { $$ = "domain"; }
| DOUBLE { $$ = "double"; }
| DROP { $$ = "drop"; }
| EACH { $$ = "each"; }
diff --git a/src/backend/parser/keywords.c b/src/backend/parser/keywords.c
index eaa0f7fa2b0..02aff543d02 100644
--- a/src/backend/parser/keywords.c
+++ b/src/backend/parser/keywords.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.101 2002/03/05 05:33:15 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.102 2002/03/06 20:34:50 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -97,6 +97,7 @@ static ScanKeyword ScanKeywords[] = {
{"desc", DESC},
{"distinct", DISTINCT},
{"do", DO},
+ {"domain", DOMAIN_P},
{"double", DOUBLE},
{"drop", DROP},
{"each", EACH},
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c
index e81edb3efc5..8586d5e5cca 100644
--- a/src/backend/parser/parse_coerce.c
+++ b/src/backend/parser/parse_coerce.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.64 2001/10/25 05:49:39 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.65 2002/03/06 20:34:51 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -38,6 +38,7 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
{
Node *result;
+
if (targetTypeId == inputTypeId ||
targetTypeId == InvalidOid ||
node == NULL)
@@ -605,3 +606,32 @@ PreferredType(CATEGORY category, Oid type)
}
return result;
} /* PreferredType() */
+
+
+/*
+ * If the targetTypeId is a domain, we really want to coerce
+ * the tuple to the domain type -- not the domain itself
+ */
+Oid
+getBaseType(Oid inType)
+{
+ HeapTuple tup;
+ Form_pg_type typTup;
+
+ tup = SearchSysCache(TYPEOID,
+ ObjectIdGetDatum(inType),
+ 0, 0, 0);
+
+ typTup = ((Form_pg_type) GETSTRUCT(tup));
+
+ /*
+ * Assume that typbasetype exists and is a base type, where inType
+ * was a domain
+ */
+ if (typTup->typtype == 'd')
+ inType = typTup->typbasetype;
+
+ ReleaseSysCache(tup);
+
+ return inType;
+} \ No newline at end of file
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 339999c0c63..b095fa44b87 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.105 2001/11/12 20:05:24 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.106 2002/03/06 20:34:52 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1027,7 +1027,8 @@ parser_typecast_expression(ParseState *pstate,
if (inputType != targetType)
{
expr = CoerceTargetExpr(pstate, expr, inputType,
- targetType, typename->typmod);
+ getBaseType(targetType),
+ typename->typmod);
if (expr == NULL)
elog(ERROR, "Cannot cast type '%s' to '%s'",
format_type_be(inputType),
@@ -1039,7 +1040,7 @@ parser_typecast_expression(ParseState *pstate,
* as well as a type coercion.
*/
expr = coerce_type_typmod(pstate, expr,
- targetType, typename->typmod);
+ getBaseType(targetType), typename->typmod);
return expr;
}