aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/view.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-03-19 20:29:08 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-03-19 20:30:08 -0400
commitb310b6e31ce5aa9e456c43c0e8e93248b0c84c02 (patch)
treee5168fcfdb231a9889e87e309f38a9e0f05a7896 /src/backend/commands/view.c
parent025f4c72f029242a6aaf3f14bb6d7da4ce070f72 (diff)
downloadpostgresql-b310b6e31ce5aa9e456c43c0e8e93248b0c84c02.tar.gz
postgresql-b310b6e31ce5aa9e456c43c0e8e93248b0c84c02.zip
Revise collation derivation method and expression-tree representation.
All expression nodes now have an explicit output-collation field, unless they are known to only return a noncollatable data type (such as boolean or record). Also, nodes that can invoke collation-aware functions store a separate field that is the collation value to pass to the function. This avoids confusion that arises when a function has collatable inputs and noncollatable output type, or vice versa. Also, replace the parser's on-the-fly collation assignment method with a post-pass over the completed expression tree. This allows us to use a more complex (and hopefully more nearly spec-compliant) assignment rule without paying for it in extra storage in every expression node. Fix assorted bugs in the planner's handling of collations by making collation one of the defining properties of an EquivalenceClass and by converting CollateExprs into discardable RelabelType nodes during expression preprocessing.
Diffstat (limited to 'src/backend/commands/view.c')
-rw-r--r--src/backend/commands/view.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c
index 794a56e84de..250d02605cf 100644
--- a/src/backend/commands/view.c
+++ b/src/backend/commands/view.c
@@ -129,14 +129,22 @@ DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace)
def->raw_default = NULL;
def->cooked_default = NULL;
def->collClause = NULL;
+ def->collOid = exprCollation((Node *) tle->expr);
/*
- * XXX Temporary kluge to make regression tests pass. We should
- * be able to trust the result of exprCollation more than this.
+ * It's possible that the column is of a collatable type but the
+ * collation could not be resolved, so double-check.
*/
if (type_is_collatable(exprType((Node *) tle->expr)))
- def->collOid = exprCollation((Node *) tle->expr);
+ {
+ if (!OidIsValid(def->collOid))
+ ereport(ERROR,
+ (errcode(ERRCODE_INDETERMINATE_COLLATION),
+ errmsg("no collation was derived for view column \"%s\"",
+ def->colname),
+ errhint("Use the COLLATE clause to set the collation explicitly.")));
+ }
else
- def->collOid = InvalidOid;
+ Assert(!OidIsValid(def->collOid));
def->constraints = NIL;
attrList = lappend(attrList, def);