summaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/copy.c67
-rw-r--r--src/backend/commands/typecmds.c28
2 files changed, 13 insertions, 82 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index af21d565f1..2b49094bea 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.262 2006/04/04 19:35:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.263 2006/04/05 22:11:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1545,9 +1545,7 @@ CopyFrom(CopyState cstate)
FmgrInfo oid_in_function;
Oid *typioparams;
Oid oid_typioparam;
- ExprState **constraintexprs;
bool *force_notnull;
- bool hasConstraints = false;
int attnum;
int i;
Oid in_func_oid;
@@ -1608,7 +1606,6 @@ CopyFrom(CopyState cstate)
typioparams = (Oid *) palloc(num_phys_attrs * sizeof(Oid));
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *));
- constraintexprs = (ExprState **) palloc0(num_phys_attrs * sizeof(ExprState *));
force_notnull = (bool *) palloc(num_phys_attrs * sizeof(bool));
for (attnum = 1; attnum <= num_phys_attrs; attnum++)
@@ -1646,35 +1643,6 @@ CopyFrom(CopyState cstate)
num_defaults++;
}
}
-
- /* If it's a domain type, set up to check domain constraints */
- if (get_typtype(attr[attnum - 1]->atttypid) == 'd')
- {
- Param *prm;
- Node *node;
-
- /*
- * Easiest way to do this is to use parse_coerce.c to set up an
- * expression that checks the constraints. (At present, the
- * expression might contain a length-coercion-function call and/or
- * CoerceToDomain nodes.) The bottom of the expression is a Param
- * node so that we can fill in the actual datum during the data
- * input loop.
- */
- prm = makeNode(Param);
- prm->paramkind = PARAM_EXEC;
- prm->paramid = 0;
- prm->paramtype = getBaseType(attr[attnum - 1]->atttypid);
-
- node = coerce_to_domain((Node *) prm,
- prm->paramtype,
- attr[attnum - 1]->atttypid,
- COERCE_IMPLICIT_CAST, false, false);
-
- constraintexprs[attnum - 1] = ExecPrepareExpr((Expr *) node,
- estate);
- hasConstraints = true;
- }
}
/* Prepare to catch AFTER triggers. */
@@ -1743,11 +1711,6 @@ CopyFrom(CopyState cstate)
nfields = file_has_oids ? (attr_count + 1) : attr_count;
field_strings = (char **) palloc(nfields * sizeof(char *));
- /* Make room for a PARAM_EXEC value for domain constraint checks */
- if (hasConstraints)
- econtext->ecxt_param_exec_vals = (ParamExecData *)
- palloc0(sizeof(ParamExecData));
-
/* Initialize state variables */
cstate->fe_eof = false;
cstate->eol_type = EOL_UNKNOWN;
@@ -1942,33 +1905,6 @@ CopyFrom(CopyState cstate)
nulls[defmap[i]] = ' ';
}
- /* Next apply any domain constraints */
- if (hasConstraints)
- {
- ParamExecData *prmdata = &econtext->ecxt_param_exec_vals[0];
-
- for (i = 0; i < num_phys_attrs; i++)
- {
- ExprState *exprstate = constraintexprs[i];
-
- if (exprstate == NULL)
- continue; /* no constraint for this attr */
-
- /* Insert current row's value into the Param value */
- prmdata->value = values[i];
- prmdata->isnull = (nulls[i] == 'n');
-
- /*
- * Execute the constraint expression. Allow the expression to
- * replace the value (consider e.g. a timestamp precision
- * restriction).
- */
- values[i] = ExecEvalExpr(exprstate, econtext,
- &isnull, NULL);
- nulls[i] = isnull ? 'n' : ' ';
- }
- }
-
/* And now we can form the input tuple. */
tuple = heap_formtuple(tupDesc, values, nulls);
@@ -2043,7 +1979,6 @@ CopyFrom(CopyState cstate)
pfree(typioparams);
pfree(defmap);
pfree(defexprs);
- pfree(constraintexprs);
pfree(force_notnull);
ExecDropSingleTupleTableSlot(slot);
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 83143496db..21546d1c8b 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.89 2006/03/14 22:48:18 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.90 2006/04/05 22:11:55 tgl Exp $
*
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
@@ -536,6 +536,7 @@ DefineDomain(CreateDomainStmt *stmt)
Oid sendProcedure;
Oid analyzeProcedure;
bool byValue;
+ Oid typelem;
char delimiter;
char alignment;
char storage;
@@ -547,7 +548,6 @@ DefineDomain(CreateDomainStmt *stmt)
char *defaultValueBin = NULL;
bool typNotNull = false;
bool nullDefined = false;
- Oid basetypelem;
int32 typNDims = list_length(stmt->typename->arrayBounds);
HeapTuple typeTup;
List *schema = stmt->constraints;
@@ -589,12 +589,12 @@ DefineDomain(CreateDomainStmt *stmt)
basetypeoid = HeapTupleGetOid(typeTup);
/*
- * Base type must be a plain base type. Domains over pseudo types would
- * create a security hole. Domains of domains might be made to work in
- * the future, but not today. Ditto for domains over complex types.
+ * Base type must be a plain base type or another domain. Domains over
+ * pseudotypes would create a security hole. Domains over composite
+ * types might be made to work in the future, but not today.
*/
typtype = baseType->typtype;
- if (typtype != 'b')
+ if (typtype != 'b' && typtype != 'd')
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("\"%s\" is not a valid base type for a domain",
@@ -612,13 +612,16 @@ DefineDomain(CreateDomainStmt *stmt)
/* Storage Length */
internalLength = baseType->typlen;
+ /* Array element type (in case base type is an array) */
+ typelem = baseType->typelem;
+
/* Array element Delimiter */
delimiter = baseType->typdelim;
/* I/O Functions */
- inputProcedure = baseType->typinput;
+ inputProcedure = F_DOMAIN_IN;
outputProcedure = baseType->typoutput;
- receiveProcedure = baseType->typreceive;
+ receiveProcedure = F_DOMAIN_RECV;
sendProcedure = baseType->typsend;
/* Analysis function */
@@ -637,13 +640,6 @@ DefineDomain(CreateDomainStmt *stmt)
defaultValueBin = DatumGetCString(DirectFunctionCall1(textout, datum));
/*
- * Pull out the typelem name of the parent OID.
- *
- * This is what enables us to make a domain of an array
- */
- basetypelem = baseType->typelem;
-
- /*
* Run through constraints manually to avoid the additional processing
* conducted by DefineRelation() and friends.
*/
@@ -776,7 +772,7 @@ DefineDomain(CreateDomainStmt *stmt)
receiveProcedure, /* receive procedure */
sendProcedure, /* send procedure */
analyzeProcedure, /* analyze procedure */
- basetypelem, /* element type ID */
+ typelem, /* element type ID */
basetypeoid, /* base type ID */
defaultValue, /* default type value (text) */
defaultValueBin, /* default type value (binary) */