1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Clean up handling of COLLATE clauses in index column definitions.

Ensure that COLLATE at the top level of an index expression is treated the
same as a grammatically separate COLLATE.  Fix bogus reverse-parsing logic
in pg_get_indexdef.
This commit is contained in:
Tom Lane
2011-03-24 15:29:52 -04:00
parent 472671e133
commit 3bba9ce945
6 changed files with 94 additions and 70 deletions

View File

@ -794,7 +794,6 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
List *context;
Oid indrelid;
int keyno;
Oid keycoltype;
Datum indcollDatum;
Datum indclassDatum;
Datum indoptionDatum;
@ -902,6 +901,8 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
{
AttrNumber attnum = idxrec->indkey.values[keyno];
int16 opt = indoption->values[keyno];
Oid keycoltype;
Oid keycolcollation;
if (!colno)
appendStringInfoString(&buf, sep);
@ -916,6 +917,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
if (!colno || colno == keyno + 1)
appendStringInfoString(&buf, quote_identifier(attname));
keycoltype = get_atttype(indrelid, attnum);
keycolcollation = get_attcollation(indrelid, attnum);
}
else
{
@ -939,16 +941,18 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
appendStringInfo(&buf, "(%s)", str);
}
keycoltype = exprType(indexkey);
keycolcollation = exprCollation(indexkey);
}
if (!attrsOnly && (!colno || colno == keyno + 1))
{
Oid coll;
Oid indcoll;
/* Add collation, if not default */
coll = indcollation->values[keyno];
if (coll && coll != DEFAULT_COLLATION_OID && coll != get_attcollation(indrelid, attnum))
appendStringInfo(&buf, " COLLATE %s", generate_collation_name((indcollation->values[keyno])));
/* Add collation, if not default for column */
indcoll = indcollation->values[keyno];
if (OidIsValid(indcoll) && indcoll != keycolcollation)
appendStringInfo(&buf, " COLLATE %s",
generate_collation_name((indcoll)));
/* Add the operator class name, if not default */
get_opclass_name(indclass->values[keyno], keycoltype, &buf);
@ -6646,7 +6650,8 @@ get_from_clause_coldeflist(List *names, List *types, List *typmods, List *collat
quote_identifier(attname),
format_type_with_typemod(atttypid, atttypmod));
if (attcollation && attcollation != DEFAULT_COLLATION_OID)
appendStringInfo(buf, " COLLATE %s", generate_collation_name(attcollation));
appendStringInfo(buf, " COLLATE %s",
generate_collation_name(attcollation));
i++;
}