PostgreSQL Source Code: src/backend/parser/parse_collate.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42
49
50
51
52
53
54
55
56typedef enum
57{
63
64typedef struct
65{
70
74
80 int location,
81 Oid collation2,
82 int location2,
90
91
92
93
94
95
96
97
98
99
100void
102{
103
104
105
106
107
108
111 pstate,
114}
115
116
117
118
119
120
121
122
123
124
125static bool
127{
128
129 if (node == NULL)
130 return false;
131
132
133
134
135
137 return false;
138
141 else
143
144 return false;
145}
146
147
148
149
150
151
152
153
154void
156{
158
159 foreach(lc, exprs)
160 {
162
164 }
165}
166
167
168
169
170
171
172
173
174
175
176void
178{
180
181
182 context.pstate = pstate;
186
187
189}
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
209{
211
212
213 context.pstate = pstate;
217
218
220
221
223 {
224 if (none_ok)
227 (errcode(ERRCODE_COLLATION_MISMATCH),
228 errmsg("collation mismatch between implicit collations \"%s\" and \"%s\"",
231 errhint("You can choose the collation by applying the COLLATE clause to one or both expressions."),
233 }
234
235
236
237
238
239
241}
242
243
244
245
246
247
248
249
250
251
252
253
254static bool
256{
258 Oid collation;
260 int location;
261
262
263 if (node == NULL)
264 return false;
265
266
267
268
269
270
275
278
279
280
281
282
283
284
286 {
287 case T_CollateExpr:
288 {
289
290
291
292
293
295
298 &loccontext);
299
300 collation = expr->collOid;
304 }
305 break;
306 case T_FieldSelect:
307 {
308
309
310
311
312
313
314
316
317
320 &loccontext);
321
323 {
324
325
326 collation = expr->resultcollid;
329 }
330 else
331 {
332
335 location = -1;
336 }
337 }
338 break;
339 case T_RowExpr:
340 {
341
342
343
344
345
347
349
350
351
352
353
354
355 return false;
356 }
357 case T_RowCompareExpr:
358 {
359
360
361
362
363
364
369
371 {
374 Oid coll;
375
378 true);
380 }
381 expr->inputcollids = colls;
382
383
384
385
386
387
388 return false;
389 }
390 case T_CoerceToDomain:
391 {
392
393
394
395
396
397
398
399
402
403
406 &loccontext);
407
409 {
410
411 if (typcollation == DEFAULT_COLLATION_OID)
412 {
413
414 collation = loccontext.collation;
415 strength = loccontext.strength;
416 location = loccontext.location;
417 }
418 else
419 {
420
421 collation = typcollation;
424 }
425 }
426 else
427 {
428
431 location = -1;
432 }
433
434
435
436
437
440 else
442 }
443 break;
444 case T_TargetEntry:
447 &loccontext);
448
449
450
451
452
453
454 collation = loccontext.collation;
455 strength = loccontext.strength;
456 location = loccontext.location;
457
458
459
460
461
462
463
464
465
466
467
468
469
470
472 ((TargetEntry *) node)->ressortgroupref != 0)
474 (errcode(ERRCODE_COLLATION_MISMATCH),
475 errmsg("collation mismatch between implicit collations \"%s\" and \"%s\"",
478 errhint("You can choose the collation by applying the COLLATE clause to one or both expressions."),
481 break;
482 case T_InferenceElem:
483 case T_RangeTblRef:
484 case T_JoinExpr:
485 case T_FromExpr:
486 case T_OnConflictExpr:
487 case T_SortGroupClause:
488 case T_MergeAction:
491 &loccontext);
492
493
494
495
496
497
498
499 return false;
500 case T_Query:
501 {
502
503
504
505
506
507
508
509
510
511
512
515
517 return false;
519 if (tent->resjunk)
520 return false;
521
523
526 }
527 break;
528 case T_List:
531 &loccontext);
532
533
534
535
536
537 collation = loccontext.collation;
538 strength = loccontext.strength;
539 location = loccontext.location;
540 break;
541
542 case T_Var:
543 case T_Const:
544 case T_Param:
545 case T_CoerceToDomainValue:
546 case T_CaseTestExpr:
547 case T_SetToDefault:
548 case T_CurrentOfExpr:
549
550
551
552
553
554
555
557
558
559
560
561
562
563
564
565
566
569 else
572 break;
573
574 default:
575 {
576
577
578
579
580 Oid typcollation;
581
582
583
584
585
586
588 {
589 case T_Aggref:
590 {
591
592
593
594
595
596
597
599
600 switch (aggref->aggkind)
601 {
602 case AGGKIND_NORMAL:
604 &loccontext);
605 break;
606 case AGGKIND_ORDERED_SET:
608 &loccontext);
609 break;
610 case AGGKIND_HYPOTHETICAL:
612 &loccontext);
613 break;
614 default:
615 elog(ERROR, "unrecognized aggkind: %d",
616 (int) aggref->aggkind);
617 }
618
621 }
622 break;
623 case T_WindowFunc:
624 {
625
626
627
628
630
632 &loccontext);
633
636 }
637 break;
638 case T_CaseExpr:
639 {
640
641
642
643
644
645
646
647
650
651 foreach(lc, expr->args)
652 {
654
655
656
657
658
659
660
661
663 &loccontext);
665 &loccontext);
666 }
668 &loccontext);
669 }
670 break;
671 case T_SubscriptingRef:
672 {
673
674
675
676
677
678
679
680
681
683
689 &loccontext);
691 &loccontext);
692 }
693 break;
694 default:
695
696
697
698
699
702 &loccontext);
703 break;
704 }
705
706
707
708
711 {
712
714 {
715
716 collation = loccontext.collation;
717 strength = loccontext.strength;
718 location = loccontext.location;
719 }
720 else
721 {
722
723
724
725
726
727
728 collation = typcollation;
731 }
732 }
733 else
734 {
735
738 location = -1;
739 }
740
741
742
743
744
745
748 else
750
751
752
753
754
757 else
759 }
760 break;
761 }
762
763
764
765
767 strength,
768 location,
771 context);
772
773 return false;
774}
775
776
777
778
779static void
782 int location,
783 Oid collation2,
784 int location2,
786{
787
788
789
790
791
792 if (strength > context->strength)
793 {
794
796 context->strength = strength;
797 context->location = location;
798
800 {
803 }
804 }
805 else if (strength == context->strength)
806 {
807
808 switch (strength)
809 {
811
812 break;
814 if (collation != context->collation)
815 {
816
817
818
819 if (context->collation == DEFAULT_COLLATION_OID)
820 {
821
823 context->strength = strength;
824 context->location = location;
825 }
826 else if (collation != DEFAULT_COLLATION_OID)
827 {
828
829
830
831
832
833
834
838 }
839 }
840 break;
842
843 break;
845 if (collation != context->collation)
846 {
847
848
849
850
851
852
854 (errcode(ERRCODE_COLLATION_MISMATCH),
855 errmsg("collation mismatch between explicit collations \"%s\" and \"%s\"",
859 }
860 break;
861 }
862 }
863}
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880static void
883{
885
886
888
889
890 foreach(lc, aggref->args)
891 {
893
894 if (tle->resjunk)
896 else
898 }
899}
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918static void
921{
922 bool merge_sort_collations;
924
925
926 merge_sort_collations = (list_length(aggref->args) == 1 &&
928
929
931 loccontext);
932
933
934 foreach(lc, aggref->args)
935 {
937
938 if (merge_sort_collations)
940 else
942 }
943}
944
945
946
947
948
949
950
951
952
953
954static void
957{
960 bool merge_sort_collations;
961 int extra_args;
962
963
964 merge_sort_collations = (list_length(aggref->args) == 1 &&
966
967
969 Assert(extra_args >= 0);
970 while (extra_args-- > 0)
971 {
974 }
975
976
977 while (h_cell && s_cell)
978 {
982
983
984
985
986
987
988
989
994
997
1000
1001
1004 (errcode(ERRCODE_COLLATION_MISMATCH),
1005 errmsg("collation mismatch between implicit collations \"%s\" and \"%s\"",
1008 errhint("You can choose the collation by applying the COLLATE clause to one or both expressions."),
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1033 {
1040 }
1041
1042
1043
1044
1045
1046 if (merge_sort_collations)
1052 loccontext);
1053
1055 s_cell = lnext(aggref->args, s_cell);
1056 }
1057 Assert(h_cell == NULL && s_cell == NULL);
1058}
#define OidIsValid(objectId)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Assert(PointerIsAligned(start, uint64))
List * lappend_oid(List *list, Oid datum)
Oid get_func_variadictype(Oid funcid)
Oid get_typcollation(Oid typid)
char * get_collation_name(Oid colloid)
RelabelType * makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat)
Oid exprType(const Node *expr)
void exprSetCollation(Node *expr, Oid collation)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
void exprSetInputCollation(Node *expr, Oid inputcollation)
int exprLocation(const Node *expr)
#define QTW_IGNORE_CTE_SUBQUERIES
#define query_tree_walker(q, w, c, f)
#define expression_tree_walker(n, w, c)
#define QTW_IGNORE_RANGE_TABLE
#define IsA(nodeptr, _type_)
void assign_list_collations(ParseState *pstate, List *exprs)
Oid select_common_collation(ParseState *pstate, List *exprs, bool none_ok)
static bool assign_collations_walker(Node *node, assign_collations_context *context)
static void assign_aggregate_collations(Aggref *aggref, assign_collations_context *loccontext)
static bool assign_query_collations_walker(Node *node, ParseState *pstate)
void assign_query_collations(ParseState *pstate, Query *query)
static void merge_collation_state(Oid collation, CollateStrength strength, int location, Oid collation2, int location2, assign_collations_context *context)
static void assign_ordered_set_collations(Aggref *aggref, assign_collations_context *loccontext)
void assign_expr_collations(ParseState *pstate, Node *expr)
static void assign_hypothetical_collations(Aggref *aggref, assign_collations_context *loccontext)
int parser_errposition(ParseState *pstate, int location)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
#define forboth(cell1, list1, cell2, list2)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make2(x1, x2)