MCPcopy Create free account
hub / github.com/apache/cloudberry / select_common_collation

Function select_common_collation

src/backend/parser/parse_collate.c:207–244  ·  view source on GitHub ↗

* select_common_collation() * Identify a common collation for a list of expressions. * * The expressions should all return the same datatype, else this is not * terribly meaningful. * * none_ok means that it is permitted to return InvalidOid, indicating that * no common collation could be identified, even for collatable datatypes. * Otherwise, an error is thrown for conflict of implicit c

Source from the content-addressed store, hash-verified

205 * operations").
206 */
207Oid
208select_common_collation(ParseState *pstate, List *exprs, bool none_ok)
209{
210 assign_collations_context context;
211
212 /* initialize context for tree walk */
213 context.pstate = pstate;
214 context.collation = InvalidOid;
215 context.strength = COLLATE_NONE;
216 context.location = -1;
217
218 context.collation2 = InvalidOid;
219 context.location2 = -1;
220
221 /* and away we go */
222 (void) assign_collations_walker((Node *) exprs, &context);
223
224 /* deal with collation conflict */
225 if (context.strength == COLLATE_CONFLICT)
226 {
227 if (none_ok)
228 return InvalidOid;
229 ereport(ERROR,
230 (errcode(ERRCODE_COLLATION_MISMATCH),
231 errmsg("collation mismatch between implicit collations \"%s\" and \"%s\"",
232 get_collation_name(context.collation),
233 get_collation_name(context.collation2)),
234 errhint("You can choose the collation by applying the COLLATE clause to one or both expressions."),
235 parser_errposition(context.pstate, context.location2)));
236 }
237
238 /*
239 * Note: if strength is still COLLATE_NONE, we'll return InvalidOid, but
240 * that's okay because it must mean none of the expressions returned
241 * collatable datatypes.
242 */
243 return context.collation;
244}
245
246/*
247 * assign_collations_walker()

Callers 4

transformValuesClauseFunction · 0.85
coerceSetOpTypesFunction · 0.85
analyzeCTEFunction · 0.85
assign_collations_walkerFunction · 0.85

Calls 6

assign_collations_walkerFunction · 0.85
get_collation_nameFunction · 0.85
parser_errpositionFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
errhintFunction · 0.50

Tested by

no test coverage detected