diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-24 15:29:52 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-24 15:29:52 -0400 |
commit | 3bba9ce945a702ab116fcedb9c0b970ecd69c9dd (patch) | |
tree | 577ec34231982a915e13db6ea8ed98521ebc2150 /src/backend/utils/adt/ruleutils.c | |
parent | 472671e133da77f280e87cb47c6544c75572df6b (diff) | |
download | postgresql-3bba9ce945a702ab116fcedb9c0b970ecd69c9dd.tar.gz postgresql-3bba9ce945a702ab116fcedb9c0b970ecd69c9dd.zip |
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.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 573c8dd4104..621f1eb24ae 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -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++; } |