From a051ef699c3ed1f89088dd6bbc2574f13d0b20eb Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 9 Mar 2011 22:38:52 -0500 Subject: 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. --- doc/src/sgml/ref/alter_table.sgml | 10 +++++++--- doc/src/sgml/ref/alter_type.sgml | 4 ++-- doc/src/sgml/ref/create_domain.sgml | 5 +++-- doc/src/sgml/ref/create_table.sgml | 6 +++--- 4 files changed, 15 insertions(+), 10 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index b8c4c507a2c..c1948624d70 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -32,9 +32,9 @@ ALTER TABLE name where action is one of: - ADD [ COLUMN ] column data_type [ column_constraint [ ... ] ] + ADD [ COLUMN ] column data_type [ COLLATE collation ] [ column_constraint [ ... ] ] DROP [ COLUMN ] [ IF EXISTS ] column [ RESTRICT | CASCADE ] - ALTER [ COLUMN ] column [ SET DATA ] TYPE type [ USING expression ] + ALTER [ COLUMN ] column [ SET DATA ] TYPE data_type [ COLLATE collation ] [ USING expression ] ALTER [ COLUMN ] column SET DEFAULT expression ALTER [ COLUMN ] column DROP DEFAULT ALTER [ COLUMN ] column { SET | DROP } NOT NULL @@ -115,7 +115,11 @@ ALTER TABLE name This form changes the type of a column of a table. Indexes and simple table constraints involving the column will be automatically converted to use the new column type by reparsing the originally - supplied expression. The optional USING + supplied expression. + The optional COLLATE clause specifies a collation + for the new column; if omitted, the collation is the default for the + new column type. + The optional USING clause specifies how to compute the new column value from the old; if omitted, the default conversion is the same as an assignment cast from old data type to new. A USING diff --git a/doc/src/sgml/ref/alter_type.sgml b/doc/src/sgml/ref/alter_type.sgml index 09db0cc8b2d..e889ffbc352 100644 --- a/doc/src/sgml/ref/alter_type.sgml +++ b/doc/src/sgml/ref/alter_type.sgml @@ -32,9 +32,9 @@ ALTER TYPE name ADD VALUE where action is one of: - ADD ATTRIBUTE attribute_name data_type [ CASCADE | RESTRICT ] + ADD ATTRIBUTE attribute_name data_type [ COLLATE collation ] [ CASCADE | RESTRICT ] DROP ATTRIBUTE [ IF EXISTS ] attribute_name [ CASCADE | RESTRICT ] - ALTER ATTRIBUTE attribute_name [ SET DATA ] TYPE data_type [ CASCADE | RESTRICT ] + ALTER ATTRIBUTE attribute_name [ SET DATA ] TYPE data_type [ COLLATE collation ] [ CASCADE | RESTRICT ] diff --git a/doc/src/sgml/ref/create_domain.sgml b/doc/src/sgml/ref/create_domain.sgml index 83be889c6d9..2300edefe3a 100644 --- a/doc/src/sgml/ref/create_domain.sgml +++ b/doc/src/sgml/ref/create_domain.sgml @@ -89,8 +89,9 @@ CREATE DOMAIN name [ AS ] An optional collation for the domain. If no collation is - specified, the database default collation is used (which can - be overridden when the domain is used to define a column). + specified, the underlying data type's default collation is used. + The underlying type must be collatable when COLLATE + is specified. diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index 9d2d99ad2e3..0fbe1160972 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -248,9 +248,9 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI COLLATE collation - The COLLATE clause assigns a nondefault collation to - the column. By default, the locale settings of the database are - used. + The COLLATE clause assigns a collation to + the column (which must be of a collatable data type). + If not specified, the column data type's default collation is used. -- cgit v1.2.3