diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-09 22:38:52 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-09 22:39:20 -0500 |
commit | a051ef699c3ed1f89088dd6bbc2574f13d0b20eb (patch) | |
tree | fe7f6e5d17f704eae2d85afece0abe19ddff5ee0 /src/backend/parser/parse_expr.c | |
parent | 01752f7bba627c0c38d594b27e50238015272828 (diff) | |
download | postgresql-a051ef699c3ed1f89088dd6bbc2574f13d0b20eb.tar.gz postgresql-a051ef699c3ed1f89088dd6bbc2574f13d0b20eb.zip |
Remove collation information from TypeName, where it does not belong.
The initial collations patch treated a COLLATE spec as part of a TypeName,
following what can only be described as brain fade on the part of the SQL
committee. It's a lot more reasonable to treat COLLATE as a syntactically
separate object, so that it can be added in only the productions where it
actually belongs, rather than needing to reject it in a boatload of places
where it doesn't belong (something the original patch mostly failed to do).
In addition this change lets us meet the spec's requirement to allow
COLLATE anywhere in the clauses of a ColumnDef, and it avoids unfriendly
behavior for constructs such as "foo::type COLLATE collation".
To do this, pull collation information out of TypeName and put it in
ColumnDef instead, thus reverting most of the collation-related changes in
parse_type.c's API. I made one additional structural change, which was to
use a ColumnDef as an intermediate node in AT_AlterColumnType AlterTableCmd
nodes. This provides enough room to get rid of the "transform" wart in
AlterTableCmd too, since the ColumnDef can carry the USING expression
easily enough.
Also fix some other minor bugs that have crept in in the same areas,
like failure to copy recently-added fields of ColumnDef in copyfuncs.c.
While at it, document the formerly secret ability to specify a collation
in ALTER TABLE ALTER COLUMN TYPE, ALTER TYPE ADD ATTRIBUTE, and
ALTER TYPE ALTER ATTRIBUTE TYPE; and correct some misstatements about
what the default collation selection will be when COLLATE is omitted.
BTW, the three-parameter form of format_type() should go away too,
since it just contributes to the confusion in this area; but I'll do
that in a separate patch.
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r-- | src/backend/parser/parse_expr.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index ae565325928..7a4f8cc2497 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -147,12 +147,6 @@ transformExpr(ParseState *pstate, Node *expr) { TypeCast *tc = (TypeCast *) expr; - if (tc->typeName->collnames) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("COLLATE clause not allowed in cast target"), - parser_errposition(pstate, tc->typeName->location))); - /* * If the subject of the typecast is an ARRAY[] construct and * the target type is an array type, we invoke @@ -2116,13 +2110,16 @@ transformCollateClause(ParseState *pstate, CollateClause *c) newc->arg = (Expr *) transformExpr(pstate, (Node *) c->arg); argtype = exprType((Node *) newc->arg); - /* The unknown type is not collatable, but coerce_type() takes - * care of it separately, so we'll let it go here. */ + /* + * The unknown type is not collatable, but coerce_type() takes + * care of it separately, so we'll let it go here. + */ if (!type_is_collatable(argtype) && argtype != UNKNOWNOID) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), + (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("collations are not supported by type %s", - format_type_be(argtype)))); + format_type_be(argtype)), + parser_errposition(pstate, c->location))); newc->collOid = LookupCollation(pstate, c->collnames, c->location); newc->collnames = c->collnames; |