relid = rel->relid;
reloid = getrelid(relid, root->parse->rtable);
- get_atttypetypmod(reloid, varattno, &vartypeid, &type_mod);
- varcollid = get_attcollation(reloid, varattno);
+ get_atttypetypmodcoll(reloid, varattno, &vartypeid, &type_mod, &varcollid);
return makeVar(relid, varattno, vartypeid, type_mod, varcollid, 0);
}
temp->opfuncid = InvalidOid;
temp->opresulttype = clause->opresulttype;
temp->opretset = clause->opretset;
+ temp->opcollid = clause->opcollid;
+ temp->inputcollid = clause->inputcollid;
temp->args = list_copy(clause->args);
temp->location = clause->location;
/* Commute it --- note this modifies the temp node in-place. */
*/
clause->opno = opoid;
clause->opfuncid = InvalidOid;
- /* opresulttype and opretset are assumed not to change */
+ /* opresulttype, opretset, opcollid, inputcollid need not change */
temp = linitial(clause->args);
linitial(clause->args) = lsecond(clause->args);
state->opexpr.opfuncid = saop->opfuncid;
state->opexpr.opresulttype = BOOLOID;
state->opexpr.opretset = false;
+ state->opexpr.opcollid = InvalidOid;
+ state->opexpr.inputcollid = saop->inputcollid;
state->opexpr.args = list_copy(saop->args);
/* Set up a dummy Const node to hold the per-element values */
state->opexpr.opfuncid = saop->opfuncid;
state->opexpr.opresulttype = BOOLOID;
state->opexpr.opretset = false;
+ state->opexpr.opcollid = InvalidOid;
+ state->opexpr.inputcollid = saop->inputcollid;
state->opexpr.args = list_copy(saop->args);
/* Initialize iteration variable to first member of ArrayExpr */
* one argument.
*/
acoerce->resulttypmod = (nargs >= 2) ? targetTypMod : -1;
+ /* resultcollid will be set by parse_collate.c */
acoerce->isExplicit = isExplicit;
acoerce->coerceformat = cformat;
acoerce->location = location;
iocoerce->arg = (Expr *) node;
iocoerce->resulttype = targetTypeId;
+ /* resultcollid will be set by parse_collate.c */
iocoerce->coerceformat = cformat;
iocoerce->location = location;
bool targetIsArray,
Oid targetTypeId,
int32 targetTypMod,
+ Oid targetCollation,
ListCell *indirection,
Node *rhs,
int location);
const char *targetName,
Oid targetTypeId,
int32 targetTypMod,
+ Oid targetCollation,
List *subscripts,
bool isSlice,
ListCell *next_indirection,
false,
attrtype,
attrtypmod,
+ attrcollation,
list_head(indirection),
(Node *) expr,
location);
* targetIsArray is true if we're subscripting it. These are just for
* error reporting.
*
- * targetTypeId and targetTypMod indicate the datatype of the object to
- * be assigned to (initially the target column, later some subobject).
+ * targetTypeId, targetTypMod, targetCollation indicate the datatype and
+ * collation of the object to be assigned to (initially the target column,
+ * later some subobject).
*
* indirection is the sublist remaining to process. When it's NULL, we're
* done recursing and can just coerce and return the RHS.
bool targetIsArray,
Oid targetTypeId,
int32 targetTypMod,
+ Oid targetCollation,
ListCell *indirection,
Node *rhs,
int location)
ctest->typeId = targetTypeId;
ctest->typeMod = targetTypMod;
+ ctest->collation = targetCollation;
basenode = (Node *) ctest;
}
AttrNumber attnum;
Oid fieldTypeId;
int32 fieldTypMod;
+ Oid fieldCollation;
Assert(IsA(n, String));
targetName,
targetTypeId,
targetTypMod,
+ targetCollation,
subscripts,
isSlice,
i,
strVal(n)),
parser_errposition(pstate, location)));
- get_atttypetypmod(typrelid, attnum,
- &fieldTypeId, &fieldTypMod);
+ get_atttypetypmodcoll(typrelid, attnum,
+ &fieldTypeId, &fieldTypMod, &fieldCollation);
/* recurse to create appropriate RHS for field assign */
rhs = transformAssignmentIndirection(pstate,
false,
fieldTypeId,
fieldTypMod,
+ fieldCollation,
lnext(i),
rhs,
location);
targetName,
targetTypeId,
targetTypMod,
+ targetCollation,
subscripts,
isSlice,
NULL,
const char *targetName,
Oid targetTypeId,
int32 targetTypMod,
+ Oid targetCollation,
List *subscripts,
bool isSlice,
ListCell *next_indirection,
int32 arrayTypMod;
Oid elementTypeId;
Oid typeNeeded;
+ Oid collationNeeded;
Assert(subscripts != NIL);
/* Identify type that RHS must provide */
typeNeeded = isSlice ? arrayType : elementTypeId;
+ /*
+ * Array normally has same collation as elements, but there's an
+ * exception: we might be subscripting a domain over an array type.
+ * In that case use collation of the base type.
+ */
+ if (arrayType == targetTypeId)
+ collationNeeded = targetCollation;
+ else
+ collationNeeded = get_typcollation(arrayType);
+
/* recurse to create appropriate RHS for array assign */
rhs = transformAssignmentIndirection(pstate,
NULL,
true,
typeNeeded,
arrayTypMod,
+ collationNeeded,
next_indirection,
rhs,
location);
{
/* Simple index column */
char *attname;
+ int32 keycoltypmod;
attname = get_relid_attribute_name(indrelid, attnum);
if (!colno || colno == keyno + 1)
appendStringInfoString(&buf, quote_identifier(attname));
- keycoltype = get_atttype(indrelid, attnum);
- keycolcollation = get_attcollation(indrelid, attnum);
+ get_atttypetypmodcoll(indrelid, attnum,
+ &keycoltype, &keycoltypmod,
+ &keycolcollation);
}
else
{
}
/*
- * get_attcollation
+ * get_atttypetypmodcoll
*
- * Given the relation id and the attribute number,
- * return the "attcollation" field from the attribute relation.
- */
-Oid
-get_attcollation(Oid relid, AttrNumber attnum)
-{
- HeapTuple tp;
-
- tp = SearchSysCache2(ATTNUM,
- ObjectIdGetDatum(relid),
- Int16GetDatum(attnum));
- if (HeapTupleIsValid(tp))
- {
- Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
- Oid result;
-
- result = att_tup->attcollation;
- ReleaseSysCache(tp);
- return result;
- }
- else
- return InvalidOid;
-}
-
-/*
- * get_atttypetypmod
- *
- * A two-fer: given the relation id and the attribute number,
- * fetch both type OID and atttypmod in a single cache lookup.
+ * A three-fer: given the relation id and the attribute number,
+ * fetch atttypid, atttypmod, and attcollation in a single cache lookup.
*
* Unlike the otherwise-similar get_atttype/get_atttypmod, this routine
* raises an error if it can't obtain the information.
*/
void
-get_atttypetypmod(Oid relid, AttrNumber attnum,
- Oid *typid, int32 *typmod)
+get_atttypetypmodcoll(Oid relid, AttrNumber attnum,
+ Oid *typid, int32 *typmod, Oid *collid)
{
HeapTuple tp;
Form_pg_attribute att_tup;
*typid = att_tup->atttypid;
*typmod = att_tup->atttypmod;
+ *collid = att_tup->attcollation;
ReleaseSysCache(tp);
}
extern AttrNumber get_attnum(Oid relid, const char *attname);
extern Oid get_atttype(Oid relid, AttrNumber attnum);
extern int32 get_atttypmod(Oid relid, AttrNumber attnum);
-extern Oid get_attcollation(Oid relid, AttrNumber attnum);
-extern void get_atttypetypmod(Oid relid, AttrNumber attnum,
- Oid *typid, int32 *typmod);
+extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum,
+ Oid *typid, int32 *typmod, Oid *collid);
extern char *get_collation_name(Oid colloid);
extern char *get_constraint_name(Oid conoid);
extern Oid get_opclass_family(Oid opclass);