PostgreSQL Source Code  git master
parse_collate.h File Reference
Include dependency graph for parse_collate.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void assign_query_collations (ParseState *pstate, Query *query)
 
void assign_list_collations (ParseState *pstate, List *exprs)
 
void assign_expr_collations (ParseState *pstate, Node *expr)
 
Oid select_common_collation (ParseState *pstate, List *exprs, bool none_ok)
 

Function Documentation

◆ assign_expr_collations()

void assign_expr_collations ( ParseState pstate,
Node expr 
)

Definition at line 177 of file parse_collate.c.

References assign_collations_walker(), COLLATE_NONE, assign_collations_context::collation, InvalidOid, assign_collations_context::location, assign_collations_context::pstate, and assign_collations_context::strength.

Referenced by AlterPolicy(), assign_aggregate_collations(), assign_collations_walker(), assign_list_collations(), assign_ordered_set_collations(), assign_query_collations_walker(), ATPrepAlterColumnType(), buildMergedJoinVar(), cookConstraint(), cookDefault(), CreatePolicy(), CreateTrigger(), domainAddConstraint(), EvaluateParams(), interpret_function_parameter_list(), transformCaseExpr(), transformIndexStmt(), transformPartitionSpec(), transformRangeTableFunc(), transformRangeTableSample(), and transformRuleStmt().

178 {
180 
181  /* initialize context for tree walk */
182  context.pstate = pstate;
183  context.collation = InvalidOid;
184  context.strength = COLLATE_NONE;
185  context.location = -1;
186 
187  /* and away we go */
188  (void) assign_collations_walker(expr, &context);
189 }
#define InvalidOid
Definition: postgres_ext.h:36
CollateStrength strength
Definition: parse_collate.c:68
static bool assign_collations_walker(Node *node, assign_collations_context *context)

◆ assign_list_collations()

void assign_list_collations ( ParseState pstate,
List exprs 
)

Definition at line 155 of file parse_collate.c.

References assign_expr_collations(), and lfirst.

Referenced by assign_collations_walker(), assign_query_collations_walker(), transformInsertStmt(), and transformRangeFunction().

156 {
157  ListCell *lc;
158 
159  foreach(lc, exprs)
160  {
161  Node *node = (Node *) lfirst(lc);
162 
163  assign_expr_collations(pstate, node);
164  }
165 }
Definition: nodes.h:512
void assign_expr_collations(ParseState *pstate, Node *expr)
#define lfirst(lc)
Definition: pg_list.h:106

◆ assign_query_collations()

void assign_query_collations ( ParseState pstate,
Query query 
)

Definition at line 101 of file parse_collate.c.

References assign_query_collations_walker(), QTW_IGNORE_CTE_SUBQUERIES, QTW_IGNORE_RANGE_TABLE, and query_tree_walker().

Referenced by transformDeleteStmt(), transformInsertStmt(), transformSelectStmt(), transformSetOperationStmt(), transformUpdateStmt(), and transformValuesClause().

102 {
103  /*
104  * We just use query_tree_walker() to visit all the contained expressions.
105  * We can skip the rangetable and CTE subqueries, though, since RTEs and
106  * subqueries had better have been processed already (else Vars referring
107  * to them would not get created with the right collation).
108  */
109  (void) query_tree_walker(query,
111  (void *) pstate,
114 }
bool query_tree_walker(Query *query, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2245
#define QTW_IGNORE_CTE_SUBQUERIES
Definition: nodeFuncs.h:21
static bool assign_query_collations_walker(Node *node, ParseState *pstate)
#define QTW_IGNORE_RANGE_TABLE
Definition: nodeFuncs.h:24

◆ select_common_collation()

Oid select_common_collation ( ParseState pstate,
List exprs,
bool  none_ok 
)

Definition at line 208 of file parse_collate.c.

References assign_collations_walker(), COLLATE_CONFLICT, COLLATE_NONE, assign_collations_context::collation, assign_collations_context::collation2, ereport, errcode(), errhint(), errmsg(), ERROR, get_collation_name(), InvalidOid, assign_collations_context::location, assign_collations_context::location2, parser_errposition(), assign_collations_context::pstate, and assign_collations_context::strength.

Referenced by assign_collations_walker(), transformSetOperationTree(), and transformValuesClause().

209 {
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  /* and away we go */
219  (void) assign_collations_walker((Node *) exprs, &context);
220 
221  /* deal with collation conflict */
222  if (context.strength == COLLATE_CONFLICT)
223  {
224  if (none_ok)
225  return InvalidOid;
226  ereport(ERROR,
227  (errcode(ERRCODE_COLLATION_MISMATCH),
228  errmsg("collation mismatch between implicit collations \"%s\" and \"%s\"",
229  get_collation_name(context.collation),
230  get_collation_name(context.collation2)),
231  errhint("You can choose the collation by applying the COLLATE clause to one or both expressions."),
232  parser_errposition(context.pstate, context.location2)));
233  }
234 
235  /*
236  * Note: if strength is still COLLATE_NONE, we'll return InvalidOid, but
237  * that's okay because it must mean none of the expressions returned
238  * collatable datatypes.
239  */
240  return context.collation;
241 }
int errhint(const char *fmt,...)
Definition: elog.c:987
char * get_collation_name(Oid colloid)
Definition: lsyscache.c:967
Definition: nodes.h:512
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
CollateStrength strength
Definition: parse_collate.c:68
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:111
int errmsg(const char *fmt,...)
Definition: elog.c:797
static bool assign_collations_walker(Node *node, assign_collations_context *context)