summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sql/sql_type.cc13
-rw-r--r--sql/sql_type.h9
-rw-r--r--sql/sql_union.cc10
3 files changed, 27 insertions, 5 deletions
diff --git a/sql/sql_type.cc b/sql/sql_type.cc
index 4906eee064d..032530deebc 100644
--- a/sql/sql_type.cc
+++ b/sql/sql_type.cc
@@ -7892,6 +7892,19 @@ bool Type_handler_string_result::Item_eq_value(THD *thd,
/***************************************************************************/
+bool Type_handler_string_result::union_element_finalize(const Item * item) const
+{
+ if (item->collation.derivation == DERIVATION_NONE)
+ {
+ my_error(ER_CANT_AGGREGATE_NCOLLATIONS, MYF(0), "UNION");
+ return true;
+ }
+ return false;
+}
+
+
+/***************************************************************************/
+
void Type_handler_var_string::
Column_definition_implicit_upgrade(Column_definition *c) const
{
diff --git a/sql/sql_type.h b/sql/sql_type.h
index da9913c1265..569e8742d2f 100644
--- a/sql/sql_type.h
+++ b/sql/sql_type.h
@@ -3356,6 +3356,14 @@ public:
virtual Field *make_conversion_table_field(TABLE *TABLE,
uint metadata,
const Field *target) const= 0;
+ /*
+ Performs the final data type validation for a UNION element,
+ after the regular "aggregation for result" was done.
+ */
+ virtual bool union_element_finalize(const Item * item) const
+ {
+ return false;
+ }
// Automatic upgrade, e.g. for ALTER TABLE t1 FORCE
virtual void Column_definition_implicit_upgrade(Column_definition *c) const
{ }
@@ -4580,6 +4588,7 @@ public:
void sortlength(THD *thd,
const Type_std_attributes *item,
SORT_FIELD_ATTR *attr) const;
+ bool union_element_finalize(const Item * item) const;
bool Column_definition_prepare_stage1(THD *thd,
MEM_ROOT *mem_root,
Column_definition *c,
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 528292e5177..e10c0af2e16 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -1085,12 +1085,12 @@ cont:
while ((type= tp++))
{
- if (type->cmp_type() == STRING_RESULT &&
- type->collation.derivation == DERIVATION_NONE)
- {
- my_error(ER_CANT_AGGREGATE_NCOLLATIONS, MYF(0), "UNION");
+ /*
+ Test if the aggregated data type is OK for a UNION element.
+ E.g. in case of string data, DERIVATION_NONE is not allowed.
+ */
+ if (type->type_handler()->union_element_finalize(type))
goto err;
- }
}
/*