src/backend/parser/parse_agg.c - Coverage Report

← Back to Overview

# src/backend/parser/parse_agg.c

Coverage: 2/2 lines (100.0%)
Total Lines
2
modified
Covered
2
100.0%
Uncovered
0
0.0%
Keyboard navigation
check_agglevels_and_constraints() lines 308-636
Modified Lines Coverage: 0/0 lines (0.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
308 | - | check_agglevels_and_constraints(ParseState *pstate, Node *expr) | -
309 | - | { | -
310 | - | List *directargs = NIL; | -
311 | - | List *args = NIL; | -
312 | - | Expr *filter = NULL; | -
313 | - | int min_varlevel; | -
314 | - | int location = -1; | -
315 | - | Index *p_levelsup; | -
316 | - | const char *err; | -
317 | - | bool errkind; | -
318 | - | bool isAgg = IsA(expr, Aggref); | -
319 | - |  | -
320 | - | if (isAgg) | -
321 | - | { | -
322 | - | Aggref *agg = (Aggref *) expr; | -
323 | - |  | -
324 | - | directargs = agg->aggdirectargs; | -
325 | - | args = agg->args; | -
326 | - | filter = agg->aggfilter; | -
327 | - | location = agg->location; | -
328 | - | p_levelsup = &agg->agglevelsup; | -
329 | - | } | -
330 | - | else | -
331 | - | { | -
332 | - | GroupingFunc *grp = (GroupingFunc *) expr; | -
333 | - |  | -
334 | - | args = grp->args; | -
335 | - | location = grp->location; | -
336 | - | p_levelsup = &grp->agglevelsup; | -
337 | - | } | -
338 | - |  | -
339 | - | /* | -
340 | - | * Check the arguments to compute the aggregate's level and detect | -
341 | - | * improper nesting. | -
342 | - | */ | -
343 | - | min_varlevel = check_agg_arguments(pstate, | -
344 | - | directargs, | -
345 | - | args, | -
346 | - | filter, | -
347 | - | location); | -
348 | - |  | -
349 | - | *p_levelsup = min_varlevel; | -
350 | - |  | -
351 | - | /* Mark the correct pstate level as having aggregates */ | -
352 | - | while (min_varlevel-- > 0) | -
353 | - | pstate = pstate->parentParseState; | -
354 | - | pstate->p_hasAggs = true; | -
355 | - |  | -
356 | - | /* | -
357 | - | * Check to see if the aggregate function is in an invalid place within | -
358 | - | * its aggregation query. | -
359 | - | * | -
360 | - | * For brevity we support two schemes for reporting an error here: set | -
361 | - | * "err" to a custom message, or set "errkind" true if the error context | -
362 | - | * is sufficiently identified by what ParseExprKindName will return, *and* | -
363 | - | * what it will return is just a SQL keyword. (Otherwise, use a custom | -
364 | - | * message to avoid creating translation problems.) | -
365 | - | */ | -
366 | - | err = NULL; | -
367 | - | errkind = false; | -
368 | - | switch (pstate->p_expr_kind) | -
369 | - | { | -
370 | - | case EXPR_KIND_NONE: | -
371 | - | Assert(false); /* can't happen */ | -
372 | - | break; | -
373 | - | case EXPR_KIND_OTHER: | -
374 | - |  | -
375 | - | /* | -
376 | - | * Accept aggregate/grouping here; caller must throw error if | -
377 | - | * wanted | -
378 | - | */ | -
379 | - | break; | -
380 | - | case EXPR_KIND_JOIN_ON: | -
381 | - | case EXPR_KIND_JOIN_USING: | -
382 | - | if (isAgg) | -
383 | - | err = _("aggregate functions are not allowed in JOIN conditions"); | -
384 | - | else | -
385 | - | err = _("grouping operations are not allowed in JOIN conditions"); | -
386 | - |  | -
387 | - | break; | -
388 | - | case EXPR_KIND_FROM_SUBSELECT: | -
389 | - |  | -
390 | - | /* | -
391 | - | * Aggregate/grouping scope rules make it worth being explicit | -
392 | - | * here | -
393 | - | */ | -
394 | - | if (isAgg) | -
395 | - | err = _("aggregate functions are not allowed in FROM clause of their own query level"); | -
396 | - | else | -
397 | - | err = _("grouping operations are not allowed in FROM clause of their own query level"); | -
398 | - |  | -
399 | - | break; | -
400 | - | case EXPR_KIND_FROM_FUNCTION: | -
401 | - | if (isAgg) | -
402 | - | err = _("aggregate functions are not allowed in functions in FROM"); | -
403 | - | else | -
404 | - | err = _("grouping operations are not allowed in functions in FROM"); | -
405 | - |  | -
406 | - | break; | -
407 | - | case EXPR_KIND_WHERE: | -
408 | - | errkind = true; | -
409 | - | break; | -
410 | - | case EXPR_KIND_POLICY: | -
411 | - | if (isAgg) | -
412 | - | err = _("aggregate functions are not allowed in policy expressions"); | -
413 | - | else | -
414 | - | err = _("grouping operations are not allowed in policy expressions"); | -
415 | - |  | -
416 | - | break; | -
417 | - | case EXPR_KIND_HAVING: | -
418 | - | /* okay */ | -
419 | - | break; | -
420 | - | case EXPR_KIND_FILTER: | -
421 | - | errkind = true; | -
422 | - | break; | -
423 | - | case EXPR_KIND_WINDOW_PARTITION: | -
424 | - | /* okay */ | -
425 | - | break; | -
426 | - | case EXPR_KIND_WINDOW_ORDER: | -
427 | - | /* okay */ | -
428 | - | break; | -
429 | - | case EXPR_KIND_WINDOW_FRAME_RANGE: | -
430 | - | if (isAgg) | -
431 | - | err = _("aggregate functions are not allowed in window RANGE"); | -
432 | - | else | -
433 | - | err = _("grouping operations are not allowed in window RANGE"); | -
434 | - |  | -
435 | - | break; | -
436 | - | case EXPR_KIND_WINDOW_FRAME_ROWS: | -
437 | - | if (isAgg) | -
438 | - | err = _("aggregate functions are not allowed in window ROWS"); | -
439 | - | else | -
440 | - | err = _("grouping operations are not allowed in window ROWS"); | -
441 | - |  | -
442 | - | break; | -
443 | - | case EXPR_KIND_WINDOW_FRAME_GROUPS: | -
444 | - | if (isAgg) | -
445 | - | err = _("aggregate functions are not allowed in window GROUPS"); | -
446 | - | else | -
447 | - | err = _("grouping operations are not allowed in window GROUPS"); | -
448 | - |  | -
449 | - | break; | -
450 | - | case EXPR_KIND_SELECT_TARGET: | -
451 | - | /* okay */ | -
452 | - | break; | -
453 | - | case EXPR_KIND_INSERT_TARGET: | -
454 | - | case EXPR_KIND_UPDATE_SOURCE: | -
455 | - | case EXPR_KIND_UPDATE_TARGET: | -
456 | - | errkind = true; | -
457 | - | break; | -
458 | - | case EXPR_KIND_MERGE_WHEN: | -
459 | - | if (isAgg) | -
460 | - | err = _("aggregate functions are not allowed in MERGE WHEN conditions"); | -
461 | - | else | -
462 | - | err = _("grouping operations are not allowed in MERGE WHEN conditions"); | -
463 | - |  | -
464 | - | break; | -
465 | - | case EXPR_KIND_GROUP_BY: | -
466 | - | errkind = true; | -
467 | - | break; | -
468 | - | case EXPR_KIND_ORDER_BY: | -
469 | - | /* okay */ | -
470 | - | break; | -
471 | - | case EXPR_KIND_DISTINCT_ON: | -
472 | - | /* okay */ | -
473 | - | break; | -
474 | - | case EXPR_KIND_LIMIT: | -
475 | - | case EXPR_KIND_OFFSET: | -
476 | - | errkind = true; | -
477 | - | break; | -
478 | - | case EXPR_KIND_RETURNING: | -
479 | - | case EXPR_KIND_MERGE_RETURNING: | -
480 | - | errkind = true; | -
481 | - | break; | -
482 | - | case EXPR_KIND_VALUES: | -
483 | - | case EXPR_KIND_VALUES_SINGLE: | -
484 | - | errkind = true; | -
485 | - | break; | -
486 | - | case EXPR_KIND_CHECK_CONSTRAINT: | -
487 | - | case EXPR_KIND_DOMAIN_CHECK: | -
488 | - | if (isAgg) | -
489 | - | err = _("aggregate functions are not allowed in check constraints"); | -
490 | - | else | -
491 | - | err = _("grouping operations are not allowed in check constraints"); | -
492 | - |  | -
493 | - | break; | -
494 | - | case EXPR_KIND_COLUMN_DEFAULT: | -
495 | - | case EXPR_KIND_FUNCTION_DEFAULT: | -
496 | - |  | -
497 | - | if (isAgg) | -
498 | - | err = _("aggregate functions are not allowed in DEFAULT expressions"); | -
499 | - | else | -
500 | - | err = _("grouping operations are not allowed in DEFAULT expressions"); | -
501 | - |  | -
502 | - | break; | -
503 | - | case EXPR_KIND_INDEX_EXPRESSION: | -
504 | - | if (isAgg) | -
505 | - | err = _("aggregate functions are not allowed in index expressions"); | -
506 | - | else | -
507 | - | err = _("grouping operations are not allowed in index expressions"); | -
508 | - |  | -
509 | - | break; | -
510 | - | case EXPR_KIND_INDEX_PREDICATE: | -
511 | - | if (isAgg) | -
512 | - | err = _("aggregate functions are not allowed in index predicates"); | -
513 | - | else | -
514 | - | err = _("grouping operations are not allowed in index predicates"); | -
515 | - |  | -
516 | - | break; | -
517 | - | case EXPR_KIND_STATS_EXPRESSION: | -
518 | - | if (isAgg) | -
519 | - | err = _("aggregate functions are not allowed in statistics expressions"); | -
520 | - | else | -
521 | - | err = _("grouping operations are not allowed in statistics expressions"); | -
522 | - |  | -
523 | - | break; | -
524 | - | case EXPR_KIND_ALTER_COL_TRANSFORM: | -
525 | - | if (isAgg) | -
526 | - | err = _("aggregate functions are not allowed in transform expressions"); | -
527 | - | else | -
528 | - | err = _("grouping operations are not allowed in transform expressions"); | -
529 | - |  | -
530 | - | break; | -
531 | - | case EXPR_KIND_EXECUTE_PARAMETER: | -
532 | - | if (isAgg) | -
533 | - | err = _("aggregate functions are not allowed in EXECUTE parameters"); | -
534 | - | else | -
535 | - | err = _("grouping operations are not allowed in EXECUTE parameters"); | -
536 | - |  | -
537 | - | break; | -
538 | - | case EXPR_KIND_TRIGGER_WHEN: | -
539 | - | if (isAgg) | -
540 | - | err = _("aggregate functions are not allowed in trigger WHEN conditions"); | -
541 | - | else | -
542 | - | err = _("grouping operations are not allowed in trigger WHEN conditions"); | -
543 | - |  | -
544 | - | break; | -
545 | - | case EXPR_KIND_PARTITION_BOUND: | -
546 | - | if (isAgg) | -
547 | - | err = _("aggregate functions are not allowed in partition bound"); | -
548 | - | else | -
549 | - | err = _("grouping operations are not allowed in partition bound"); | -
550 | - |  | -
551 | - | break; | -
552 | - | case EXPR_KIND_PARTITION_EXPRESSION: | -
553 | - | if (isAgg) | -
554 | - | err = _("aggregate functions are not allowed in partition key expressions"); | -
555 | - | else | -
556 | - | err = _("grouping operations are not allowed in partition key expressions"); | -
557 | - |  | -
558 | - | break; | -
559 | - | case EXPR_KIND_GENERATED_COLUMN: | -
560 | - |  | -
561 | - | if (isAgg) | -
562 | - | err = _("aggregate functions are not allowed in column generation expressions"); | -
563 | - | else | -
564 | - | err = _("grouping operations are not allowed in column generation expressions"); | -
565 | - |  | -
566 | - | break; | -
567 | - |  | -
568 | - | case EXPR_KIND_CALL_ARGUMENT: | -
569 | - | if (isAgg) | -
570 | - | err = _("aggregate functions are not allowed in CALL arguments"); | -
571 | - | else | -
572 | - | err = _("grouping operations are not allowed in CALL arguments"); | -
573 | - |  | -
574 | - | break; | -
575 | - |  | -
576 | - | case EXPR_KIND_COPY_WHERE: | -
577 | - | if (isAgg) | -
578 | - | err = _("aggregate functions are not allowed in COPY FROM WHERE conditions"); | -
579 | - | else | -
580 | - | err = _("grouping operations are not allowed in COPY FROM WHERE conditions"); | -
581 | - |  | -
582 | - | break; | -
583 | - |  | -
584 | - | case EXPR_KIND_CYCLE_MARK: | -
585 | - | errkind = true; | -
586 | - | break; | -
587 | - | case EXPR_KIND_FOR_PORTION: | -
588 | - | if (isAgg) | -
589 | - | err = _("aggregate functions are not allowed in FOR PORTION OF expressions"); | -
590 | - | else | -
591 | - | err = _("grouping operations are not allowed in FOR PORTION OF expressions"); | -
592 | - |  | -
593 | - | break; | -
594 | - |  | -
595 | - | case EXPR_KIND_PROPGRAPH_PROPERTY: | -
596 | - | if (isAgg) | -
597 | - | err = _("aggregate functions are not allowed in property definition expressions"); | -
598 | - | else | -
599 | - | err = _("grouping operations are not allowed in property definition expressions"); | -
600 | - | break; | c54ba27Row pattern recognition patch (parse/analysis).
601 | - |  | -
602 | - | case EXPR_KIND_RPR_DEFINE: | c54ba27Row pattern recognition patch (parse/analysis).
603 | - | errkind = true; | c54ba27Row pattern recognition patch (parse/analysis).
604 | - | break; | -
605 | - |  | -
606 | - | /* | -
607 | - | * There is intentionally no default: case here, so that the | -
608 | - | * compiler will warn if we add a new ParseExprKind without | -
609 | - | * extending this switch. If we do see an unrecognized value at | -
610 | - | * runtime, the behavior will be the same as for EXPR_KIND_OTHER, | -
611 | - | * which is sane anyway. | -
612 | - | */ | -
613 | - | } | -
614 | - |  | -
615 | - | if (err) | -
616 | - | ereport(ERROR, | -
617 | - | (errcode(ERRCODE_GROUPING_ERROR), | -
618 | - | errmsg_internal("%s", err), | -
619 | - | parser_errposition(pstate, location))); | -
620 | - |  | -
621 | - | if (errkind) | -
622 | - | { | -
623 | - | if (isAgg) | -
624 | - | /* translator: %s is name of a SQL construct, eg GROUP BY */ | -
625 | - | err = _("aggregate functions are not allowed in %s"); | -
626 | - | else | -
627 | - | /* translator: %s is name of a SQL construct, eg GROUP BY */ | -
628 | - | err = _("grouping operations are not allowed in %s"); | -
629 | - |  | -
630 | - | ereport(ERROR, | -
631 | - | (errcode(ERRCODE_GROUPING_ERROR), | -
632 | - | errmsg_internal(err, | -
633 | - | ParseExprKindName(pstate->p_expr_kind)), | -
634 | - | parser_errposition(pstate, location))); | -
635 | - | } | -
636 | - | } | -

transformWindowFuncCall() lines 897-1150
Modified Lines Coverage: 2/2 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
897 | - | transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc, | -
898 | - | WindowDef *windef) | -
899 | - | { | -
900 | - | const char *err; | -
901 | - | bool errkind; | -
902 | - |  | -
903 | - | /* | -
904 | - | * A window function call can't contain another one (but aggs are OK). XXX | -
905 | - | * is this required by spec, or just an unimplemented feature? | -
906 | - | * | -
907 | - | * Note: we don't need to check the filter expression here, because the | -
908 | - | * context checks done below and in transformAggregateCall would have | -
909 | - | * already rejected any window funcs or aggs within the filter. | -
910 | - | */ | -
911 | - | if (pstate->p_hasWindowFuncs && | -
912 | - | contain_windowfuncs((Node *) wfunc->args)) | -
913 | - | ereport(ERROR, | -
914 | - | (errcode(ERRCODE_WINDOWING_ERROR), | -
915 | - | errmsg("window function calls cannot be nested"), | -
916 | - | parser_errposition(pstate, | -
917 | - | locate_windowfunc((Node *) wfunc->args)))); | -
918 | - |  | -
919 | - | /* | -
920 | - | * Check to see if the window function is in an invalid place within the | -
921 | - | * query. | -
922 | - | * | -
923 | - | * For brevity we support two schemes for reporting an error here: set | -
924 | - | * "err" to a custom message, or set "errkind" true if the error context | -
925 | - | * is sufficiently identified by what ParseExprKindName will return, *and* | -
926 | - | * what it will return is just a SQL keyword. (Otherwise, use a custom | -
927 | - | * message to avoid creating translation problems.) | -
928 | - | */ | -
929 | - | err = NULL; | -
930 | - | errkind = false; | -
931 | - | switch (pstate->p_expr_kind) | -
932 | - | { | -
933 | - | case EXPR_KIND_NONE: | -
934 | - | Assert(false); /* can't happen */ | -
935 | - | break; | -
936 | - | case EXPR_KIND_OTHER: | -
937 | - | /* Accept window func here; caller must throw error if wanted */ | -
938 | - | break; | -
939 | - | case EXPR_KIND_JOIN_ON: | -
940 | - | case EXPR_KIND_JOIN_USING: | -
941 | - | err = _("window functions are not allowed in JOIN conditions"); | -
942 | - | break; | -
943 | - | case EXPR_KIND_FROM_SUBSELECT: | -
944 | - | /* can't get here, but just in case, throw an error */ | -
945 | - | errkind = true; | -
946 | - | break; | -
947 | - | case EXPR_KIND_FROM_FUNCTION: | -
948 | - | err = _("window functions are not allowed in functions in FROM"); | -
949 | - | break; | -
950 | - | case EXPR_KIND_WHERE: | -
951 | - | errkind = true; | -
952 | - | break; | -
953 | - | case EXPR_KIND_POLICY: | -
954 | - | err = _("window functions are not allowed in policy expressions"); | -
955 | - | break; | -
956 | - | case EXPR_KIND_HAVING: | -
957 | - | errkind = true; | -
958 | - | break; | -
959 | - | case EXPR_KIND_FILTER: | -
960 | - | errkind = true; | -
961 | - | break; | -
962 | - | case EXPR_KIND_WINDOW_PARTITION: | -
963 | - | case EXPR_KIND_WINDOW_ORDER: | -
964 | - | case EXPR_KIND_WINDOW_FRAME_RANGE: | -
965 | - | case EXPR_KIND_WINDOW_FRAME_ROWS: | -
966 | - | case EXPR_KIND_WINDOW_FRAME_GROUPS: | -
967 | - | err = _("window functions are not allowed in window definitions"); | -
968 | - | break; | -
969 | - | case EXPR_KIND_SELECT_TARGET: | -
970 | - | /* okay */ | -
971 | - | break; | -
972 | - | case EXPR_KIND_INSERT_TARGET: | -
973 | - | case EXPR_KIND_UPDATE_SOURCE: | -
974 | - | case EXPR_KIND_UPDATE_TARGET: | -
975 | - | errkind = true; | -
976 | - | break; | -
977 | - | case EXPR_KIND_MERGE_WHEN: | -
978 | - | err = _("window functions are not allowed in MERGE WHEN conditions"); | -
979 | - | break; | -
980 | - | case EXPR_KIND_GROUP_BY: | -
981 | - | errkind = true; | -
982 | - | break; | -
983 | - | case EXPR_KIND_ORDER_BY: | -
984 | - | /* okay */ | -
985 | - | break; | -
986 | - | case EXPR_KIND_DISTINCT_ON: | -
987 | - | /* okay */ | -
988 | - | break; | -
989 | - | case EXPR_KIND_LIMIT: | -
990 | - | case EXPR_KIND_OFFSET: | -
991 | - | errkind = true; | -
992 | - | break; | -
993 | - | case EXPR_KIND_RETURNING: | -
994 | - | case EXPR_KIND_MERGE_RETURNING: | -
995 | - | errkind = true; | -
996 | - | break; | -
997 | - | case EXPR_KIND_VALUES: | -
998 | - | case EXPR_KIND_VALUES_SINGLE: | -
999 | - | errkind = true; | -
1000 | - | break; | -
1001 | - | case EXPR_KIND_CHECK_CONSTRAINT: | -
1002 | - | case EXPR_KIND_DOMAIN_CHECK: | -
1003 | - | err = _("window functions are not allowed in check constraints"); | -
1004 | - | break; | -
1005 | - | case EXPR_KIND_COLUMN_DEFAULT: | -
1006 | - | case EXPR_KIND_FUNCTION_DEFAULT: | -
1007 | - | err = _("window functions are not allowed in DEFAULT expressions"); | -
1008 | - | break; | -
1009 | - | case EXPR_KIND_INDEX_EXPRESSION: | -
1010 | - | err = _("window functions are not allowed in index expressions"); | -
1011 | - | break; | -
1012 | - | case EXPR_KIND_STATS_EXPRESSION: | -
1013 | - | err = _("window functions are not allowed in statistics expressions"); | -
1014 | - | break; | -
1015 | - | case EXPR_KIND_INDEX_PREDICATE: | -
1016 | - | err = _("window functions are not allowed in index predicates"); | -
1017 | - | break; | -
1018 | - | case EXPR_KIND_ALTER_COL_TRANSFORM: | -
1019 | - | err = _("window functions are not allowed in transform expressions"); | -
1020 | - | break; | -
1021 | - | case EXPR_KIND_EXECUTE_PARAMETER: | -
1022 | - | err = _("window functions are not allowed in EXECUTE parameters"); | -
1023 | - | break; | -
1024 | - | case EXPR_KIND_TRIGGER_WHEN: | -
1025 | - | err = _("window functions are not allowed in trigger WHEN conditions"); | -
1026 | - | break; | -
1027 | - | case EXPR_KIND_PARTITION_BOUND: | -
1028 | - | err = _("window functions are not allowed in partition bound"); | -
1029 | - | break; | -
1030 | - | case EXPR_KIND_PARTITION_EXPRESSION: | -
1031 | - | err = _("window functions are not allowed in partition key expressions"); | -
1032 | - | break; | -
1033 | - | case EXPR_KIND_CALL_ARGUMENT: | -
1034 | - | err = _("window functions are not allowed in CALL arguments"); | -
1035 | - | break; | -
1036 | - | case EXPR_KIND_COPY_WHERE: | -
1037 | - | err = _("window functions are not allowed in COPY FROM WHERE conditions"); | -
1038 | - | break; | -
1039 | - | case EXPR_KIND_GENERATED_COLUMN: | -
1040 | - | err = _("window functions are not allowed in column generation expressions"); | -
1041 | - | break; | -
1042 | - | case EXPR_KIND_CYCLE_MARK: | -
1043 | - | errkind = true; | -
1044 | - | break; | -
1045 | - | case EXPR_KIND_PROPGRAPH_PROPERTY: | -
1046 | - | err = _("window functions are not allowed in property definition expressions"); | -
1047 | - | break; | -
1048 | - | case EXPR_KIND_FOR_PORTION: | -
1049 | - | err = _("window functions are not allowed in FOR PORTION OF expressions"); | -
1050 | - | break; | -
1051 | - | case EXPR_KIND_RPR_DEFINE: | c54ba27Row pattern recognition patch (parse/analysis).
1052 | - | errkind = true; | c54ba27Row pattern recognition patch (parse/analysis).
1053 | - | break; | c54ba27Row pattern recognition patch (parse/analysis).
1054 | - |  | -
1055 | - | /* | -
1056 | - | * There is intentionally no default: case here, so that the | -
1057 | - | * compiler will warn if we add a new ParseExprKind without | -
1058 | - | * extending this switch. If we do see an unrecognized value at | -
1059 | - | * runtime, the behavior will be the same as for EXPR_KIND_OTHER, | -
1060 | - | * which is sane anyway. | -
1061 | - | */ | -
1062 | - | } | -
1063 | - | if (err) | -
1064 | - | ereport(ERROR, | -
1065 | - | (errcode(ERRCODE_WINDOWING_ERROR), | -
1066 | - | errmsg_internal("%s", err), | -
1067 | - | parser_errposition(pstate, wfunc->location))); | -
1068 | - | if (errkind) | -
1069 | - | ereport(ERROR, | -
1070 | - | (errcode(ERRCODE_WINDOWING_ERROR), | -
1071 | - | /* translator: %s is name of a SQL construct, eg GROUP BY */ | -
1072 | - | errmsg("window functions are not allowed in %s", | -
1073 | - | ParseExprKindName(pstate->p_expr_kind)), | -
1074 | - | parser_errposition(pstate, wfunc->location))); | -
1075 | - |  | -
1076 | - | /* | -
1077 | - | * If the OVER clause just specifies a window name, find that WINDOW | -
1078 | - | * clause (which had better be present). Otherwise, try to match all the | -
1079 | - | * properties of the OVER clause, and make a new entry in the p_windowdefs | -
1080 | - | * list if no luck. | -
1081 | - | */ | -
1082 | - | if (windef->name) | -
1083 | - | { | -
1084 | - | Index winref = 0; | -
1085 | - | ListCell *lc; | -
1086 | - |  | -
1087 | - | Assert(windef->refname == NULL && | -
1088 | - | windef->partitionClause == NIL && | -
1089 | - | windef->orderClause == NIL && | -
1090 | - | windef->frameOptions == FRAMEOPTION_DEFAULTS); | -
1091 | - |  | -
1092 | - | foreach(lc, pstate->p_windowdefs) | -
1093 | - | { | -
1094 | - | WindowDef *refwin = (WindowDef *) lfirst(lc); | -
1095 | - |  | -
1096 | - | winref++; | -
1097 | - | if (refwin->name && strcmp(refwin->name, windef->name) == 0) | -
1098 | - | { | -
1099 | - | wfunc->winref = winref; | -
1100 | - | break; | -
1101 | - | } | -
1102 | - | } | -
1103 | - | if (lc == NULL) /* didn't find it? */ | -
1104 | - | ereport(ERROR, | -
1105 | - | (errcode(ERRCODE_UNDEFINED_OBJECT), | -
1106 | - | errmsg("window \"%s\" does not exist", windef->name), | -
1107 | - | parser_errposition(pstate, windef->location))); | -
1108 | - | } | -
1109 | - | else | -
1110 | - | { | -
1111 | - | Index winref = 0; | -
1112 | - | ListCell *lc; | -
1113 | - |  | -
1114 | - | foreach(lc, pstate->p_windowdefs) | -
1115 | - | { | -
1116 | - | WindowDef *refwin = (WindowDef *) lfirst(lc); | -
1117 | - |  | -
1118 | - | winref++; | -
1119 | - | if (refwin->refname && windef->refname && | -
1120 | - | strcmp(refwin->refname, windef->refname) == 0) | -
1121 | - | /* matched on refname */ ; | -
1122 | - | else if (!refwin->refname && !windef->refname) | -
1123 | - | /* matched, no refname */ ; | -
1124 | - | else | -
1125 | - | continue; | -
1126 | - |  | -
1127 | - | /* | -
1128 | - | * Also see similar de-duplication code in optimize_window_clauses | -
1129 | - | */ | -
1130 | - | if (equal(refwin->partitionClause, windef->partitionClause) && | -
1131 | - | equal(refwin->orderClause, windef->orderClause) && | -
1132 | - | refwin->frameOptions == windef->frameOptions && | -
1133 | - | equal(refwin->startOffset, windef->startOffset) && | -
1134 | 392 | equal(refwin->endOffset, windef->endOffset) && | c54ba27Row pattern recognition patch (parse/analysis).
1135 | 196 | equal(refwin->rpCommonSyntax, windef->rpCommonSyntax)) | c54ba27Row pattern recognition patch (parse/analysis).
1136 | - | { | -
1137 | - | /* found a duplicate window specification */ | -
1138 | - | wfunc->winref = winref; | -
1139 | - | break; | -
1140 | - | } | -
1141 | - | } | -
1142 | - | if (lc == NULL) /* didn't find it? */ | -
1143 | - | { | -
1144 | - | pstate->p_windowdefs = lappend(pstate->p_windowdefs, windef); | -
1145 | - | wfunc->winref = list_length(pstate->p_windowdefs); | -
1146 | - | } | -
1147 | - | } | -
1148 | - |  | -
1149 | - | pstate->p_hasWindowFuncs = true; | -
1150 | - | } | -