* 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
| 205 | * operations"). |
| 206 | */ |
| 207 | Oid |
| 208 | select_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() |
no test coverage detected