| Line | Hits | Source | Commit |
|---|---|---|---|
| 307 | - | check_agglevels_and_constraints(ParseState *pstate, Node *expr) | - |
| 308 | - | { | - |
| 309 | - | List *directargs = NIL; | - |
| 310 | - | List *args = NIL; | - |
| 311 | - | Expr *filter = NULL; | - |
| 312 | - | int min_varlevel; | - |
| 313 | - | int location = -1; | - |
| 314 | - | Index *p_levelsup; | - |
| 315 | - | const char *err; | - |
| 316 | - | bool errkind; | - |
| 317 | - | bool isAgg = IsA(expr, Aggref); | - |
| 318 | - | - | |
| 319 | - | if (isAgg) | - |
| 320 | - | { | - |
| 321 | - | Aggref *agg = (Aggref *) expr; | - |
| 322 | - | - | |
| 323 | - | directargs = agg->aggdirectargs; | - |
| 324 | - | args = agg->args; | - |
| 325 | - | filter = agg->aggfilter; | - |
| 326 | - | location = agg->location; | - |
| 327 | - | p_levelsup = &agg->agglevelsup; | - |
| 328 | - | } | - |
| 329 | - | else | - |
| 330 | - | { | - |
| 331 | - | GroupingFunc *grp = (GroupingFunc *) expr; | - |
| 332 | - | - | |
| 333 | - | args = grp->args; | - |
| 334 | - | location = grp->location; | - |
| 335 | - | p_levelsup = &grp->agglevelsup; | - |
| 336 | - | } | - |
| 337 | - | - | |
| 338 | - | /* | - |
| 339 | - | * Check the arguments to compute the aggregate's level and detect | - |
| 340 | - | * improper nesting. | - |
| 341 | - | */ | - |
| 342 | - | min_varlevel = check_agg_arguments(pstate, | - |
| 343 | - | directargs, | - |
| 344 | - | args, | - |
| 345 | - | filter, | - |
| 346 | - | location); | - |
| 347 | - | - | |
| 348 | - | *p_levelsup = min_varlevel; | - |
| 349 | - | - | |
| 350 | - | /* Mark the correct pstate level as having aggregates */ | - |
| 351 | - | while (min_varlevel-- > 0) | - |
| 352 | - | pstate = pstate->parentParseState; | - |
| 353 | - | pstate->p_hasAggs = true; | - |
| 354 | - | - | |
| 355 | - | /* | - |
| 356 | - | * Check to see if the aggregate function is in an invalid place within | - |
| 357 | - | * its aggregation query. | - |
| 358 | - | * | - |
| 359 | - | * For brevity we support two schemes for reporting an error here: set | - |
| 360 | - | * "err" to a custom message, or set "errkind" true if the error context | - |
| 361 | - | * is sufficiently identified by what ParseExprKindName will return, *and* | - |
| 362 | - | * what it will return is just a SQL keyword. (Otherwise, use a custom | - |
| 363 | - | * message to avoid creating translation problems.) | - |
| 364 | - | */ | - |
| 365 | - | err = NULL; | - |
| 366 | - | errkind = false; | - |
| 367 | - | switch (pstate->p_expr_kind) | - |
| 368 | - | { | - |
| 369 | - | case EXPR_KIND_NONE: | - |
| 370 | - | Assert(false); /* can't happen */ | - |
| 371 | - | break; | - |
| 372 | - | case EXPR_KIND_OTHER: | - |
| 373 | - | - | |
| 374 | - | /* | - |
| 375 | - | * Accept aggregate/grouping here; caller must throw error if | - |
| 376 | - | * wanted | - |
| 377 | - | */ | - |
| 378 | - | break; | - |
| 379 | - | case EXPR_KIND_JOIN_ON: | - |
| 380 | - | case EXPR_KIND_JOIN_USING: | - |
| 381 | - | if (isAgg) | - |
| 382 | - | err = _("aggregate functions are not allowed in JOIN conditions"); | - |
| 383 | - | else | - |
| 384 | - | err = _("grouping operations are not allowed in JOIN conditions"); | - |
| 385 | - | - | |
| 386 | - | break; | - |
| 387 | - | case EXPR_KIND_FROM_SUBSELECT: | - |
| 388 | - | - | |
| 389 | - | /* | - |
| 390 | - | * Aggregate/grouping scope rules make it worth being explicit | - |
| 391 | - | * here | - |
| 392 | - | */ | - |
| 393 | - | if (isAgg) | - |
| 394 | - | err = _("aggregate functions are not allowed in FROM clause of their own query level"); | - |
| 395 | - | else | - |
| 396 | - | err = _("grouping operations are not allowed in FROM clause of their own query level"); | - |
| 397 | - | - | |
| 398 | - | break; | - |
| 399 | - | case EXPR_KIND_FROM_FUNCTION: | - |
| 400 | - | if (isAgg) | - |
| 401 | - | err = _("aggregate functions are not allowed in functions in FROM"); | - |
| 402 | - | else | - |
| 403 | - | err = _("grouping operations are not allowed in functions in FROM"); | - |
| 404 | - | - | |
| 405 | - | break; | - |
| 406 | - | case EXPR_KIND_WHERE: | - |
| 407 | - | errkind = true; | - |
| 408 | - | break; | - |
| 409 | - | case EXPR_KIND_POLICY: | - |
| 410 | - | if (isAgg) | - |
| 411 | - | err = _("aggregate functions are not allowed in policy expressions"); | - |
| 412 | - | else | - |
| 413 | - | err = _("grouping operations are not allowed in policy expressions"); | - |
| 414 | - | - | |
| 415 | - | break; | - |
| 416 | - | case EXPR_KIND_HAVING: | - |
| 417 | - | /* okay */ | - |
| 418 | - | break; | - |
| 419 | - | case EXPR_KIND_FILTER: | - |
| 420 | - | errkind = true; | - |
| 421 | - | break; | - |
| 422 | - | case EXPR_KIND_WINDOW_PARTITION: | - |
| 423 | - | /* okay */ | - |
| 424 | - | break; | - |
| 425 | - | case EXPR_KIND_WINDOW_ORDER: | - |
| 426 | - | /* okay */ | - |
| 427 | - | break; | - |
| 428 | - | case EXPR_KIND_WINDOW_FRAME_RANGE: | - |
| 429 | - | if (isAgg) | - |
| 430 | - | err = _("aggregate functions are not allowed in window RANGE"); | - |
| 431 | - | else | - |
| 432 | - | err = _("grouping operations are not allowed in window RANGE"); | - |
| 433 | - | - | |
| 434 | - | break; | - |
| 435 | - | case EXPR_KIND_WINDOW_FRAME_ROWS: | - |
| 436 | - | if (isAgg) | - |
| 437 | - | err = _("aggregate functions are not allowed in window ROWS"); | - |
| 438 | - | else | - |
| 439 | - | err = _("grouping operations are not allowed in window ROWS"); | - |
| 440 | - | - | |
| 441 | - | break; | - |
| 442 | - | case EXPR_KIND_WINDOW_FRAME_GROUPS: | - |
| 443 | - | if (isAgg) | - |
| 444 | - | err = _("aggregate functions are not allowed in window GROUPS"); | - |
| 445 | - | else | - |
| 446 | - | err = _("grouping operations are not allowed in window GROUPS"); | - |
| 447 | - | - | |
| 448 | - | break; | - |
| 449 | - | case EXPR_KIND_SELECT_TARGET: | - |
| 450 | - | /* okay */ | - |
| 451 | - | break; | - |
| 452 | - | case EXPR_KIND_INSERT_TARGET: | - |
| 453 | - | case EXPR_KIND_UPDATE_SOURCE: | - |
| 454 | - | case EXPR_KIND_UPDATE_TARGET: | - |
| 455 | - | errkind = true; | - |
| 456 | - | break; | - |
| 457 | - | case EXPR_KIND_MERGE_WHEN: | - |
| 458 | - | if (isAgg) | - |
| 459 | - | err = _("aggregate functions are not allowed in MERGE WHEN conditions"); | - |
| 460 | - | else | - |
| 461 | - | err = _("grouping operations are not allowed in MERGE WHEN conditions"); | - |
| 462 | - | - | |
| 463 | - | break; | - |
| 464 | - | case EXPR_KIND_GROUP_BY: | - |
| 465 | - | errkind = true; | - |
| 466 | - | break; | - |
| 467 | - | case EXPR_KIND_ORDER_BY: | - |
| 468 | - | /* okay */ | - |
| 469 | - | break; | - |
| 470 | - | case EXPR_KIND_DISTINCT_ON: | - |
| 471 | - | /* okay */ | - |
| 472 | - | break; | - |
| 473 | - | case EXPR_KIND_LIMIT: | - |
| 474 | - | case EXPR_KIND_OFFSET: | - |
| 475 | - | errkind = true; | - |
| 476 | - | break; | - |
| 477 | - | case EXPR_KIND_RETURNING: | - |
| 478 | - | case EXPR_KIND_MERGE_RETURNING: | - |
| 479 | - | errkind = true; | - |
| 480 | - | break; | - |
| 481 | - | case EXPR_KIND_VALUES: | - |
| 482 | - | case EXPR_KIND_VALUES_SINGLE: | - |
| 483 | - | errkind = true; | - |
| 484 | - | break; | - |
| 485 | - | case EXPR_KIND_CHECK_CONSTRAINT: | - |
| 486 | - | case EXPR_KIND_DOMAIN_CHECK: | - |
| 487 | - | if (isAgg) | - |
| 488 | - | err = _("aggregate functions are not allowed in check constraints"); | - |
| 489 | - | else | - |
| 490 | - | err = _("grouping operations are not allowed in check constraints"); | - |
| 491 | - | - | |
| 492 | - | break; | - |
| 493 | - | case EXPR_KIND_COLUMN_DEFAULT: | - |
| 494 | - | case EXPR_KIND_FUNCTION_DEFAULT: | - |
| 495 | - | - | |
| 496 | - | if (isAgg) | - |
| 497 | - | err = _("aggregate functions are not allowed in DEFAULT expressions"); | - |
| 498 | - | else | - |
| 499 | - | err = _("grouping operations are not allowed in DEFAULT expressions"); | - |
| 500 | - | - | |
| 501 | - | break; | - |
| 502 | - | case EXPR_KIND_INDEX_EXPRESSION: | - |
| 503 | - | if (isAgg) | - |
| 504 | - | err = _("aggregate functions are not allowed in index expressions"); | - |
| 505 | - | else | - |
| 506 | - | err = _("grouping operations are not allowed in index expressions"); | - |
| 507 | - | - | |
| 508 | - | break; | - |
| 509 | - | case EXPR_KIND_INDEX_PREDICATE: | - |
| 510 | - | if (isAgg) | - |
| 511 | - | err = _("aggregate functions are not allowed in index predicates"); | - |
| 512 | - | else | - |
| 513 | - | err = _("grouping operations are not allowed in index predicates"); | - |
| 514 | - | - | |
| 515 | - | break; | - |
| 516 | - | case EXPR_KIND_STATS_EXPRESSION: | - |
| 517 | - | if (isAgg) | - |
| 518 | - | err = _("aggregate functions are not allowed in statistics expressions"); | - |
| 519 | - | else | - |
| 520 | - | err = _("grouping operations are not allowed in statistics expressions"); | - |
| 521 | - | - | |
| 522 | - | break; | - |
| 523 | - | case EXPR_KIND_ALTER_COL_TRANSFORM: | - |
| 524 | - | if (isAgg) | - |
| 525 | - | err = _("aggregate functions are not allowed in transform expressions"); | - |
| 526 | - | else | - |
| 527 | - | err = _("grouping operations are not allowed in transform expressions"); | - |
| 528 | - | - | |
| 529 | - | break; | - |
| 530 | - | case EXPR_KIND_EXECUTE_PARAMETER: | - |
| 531 | - | if (isAgg) | - |
| 532 | - | err = _("aggregate functions are not allowed in EXECUTE parameters"); | - |
| 533 | - | else | - |
| 534 | - | err = _("grouping operations are not allowed in EXECUTE parameters"); | - |
| 535 | - | - | |
| 536 | - | break; | - |
| 537 | - | case EXPR_KIND_TRIGGER_WHEN: | - |
| 538 | - | if (isAgg) | - |
| 539 | - | err = _("aggregate functions are not allowed in trigger WHEN conditions"); | - |
| 540 | - | else | - |
| 541 | - | err = _("grouping operations are not allowed in trigger WHEN conditions"); | - |
| 542 | - | - | |
| 543 | - | break; | - |
| 544 | - | case EXPR_KIND_PARTITION_BOUND: | - |
| 545 | - | if (isAgg) | - |
| 546 | - | err = _("aggregate functions are not allowed in partition bound"); | - |
| 547 | - | else | - |
| 548 | - | err = _("grouping operations are not allowed in partition bound"); | - |
| 549 | - | - | |
| 550 | - | break; | - |
| 551 | - | case EXPR_KIND_PARTITION_EXPRESSION: | - |
| 552 | - | if (isAgg) | - |
| 553 | - | err = _("aggregate functions are not allowed in partition key expressions"); | - |
| 554 | - | else | - |
| 555 | - | err = _("grouping operations are not allowed in partition key expressions"); | - |
| 556 | - | - | |
| 557 | - | break; | - |
| 558 | - | case EXPR_KIND_GENERATED_COLUMN: | - |
| 559 | - | - | |
| 560 | - | if (isAgg) | - |
| 561 | - | err = _("aggregate functions are not allowed in column generation expressions"); | - |
| 562 | - | else | - |
| 563 | - | err = _("grouping operations are not allowed in column generation expressions"); | - |
| 564 | - | - | |
| 565 | - | break; | - |
| 566 | - | - | |
| 567 | - | case EXPR_KIND_CALL_ARGUMENT: | - |
| 568 | - | if (isAgg) | - |
| 569 | - | err = _("aggregate functions are not allowed in CALL arguments"); | - |
| 570 | - | else | - |
| 571 | - | err = _("grouping operations are not allowed in CALL arguments"); | - |
| 572 | - | - | |
| 573 | - | break; | - |
| 574 | - | - | |
| 575 | - | case EXPR_KIND_COPY_WHERE: | - |
| 576 | - | if (isAgg) | - |
| 577 | - | err = _("aggregate functions are not allowed in COPY FROM WHERE conditions"); | - |
| 578 | - | else | - |
| 579 | - | err = _("grouping operations are not allowed in COPY FROM WHERE conditions"); | - |
| 580 | - | - | |
| 581 | - | break; | - |
| 582 | - | - | |
| 583 | - | case EXPR_KIND_CYCLE_MARK: | - |
| 584 | - | errkind = true; | - |
| 585 | - | break; | - |
| 586 | - | - | |
| 587 | 0 | case EXPR_KIND_PROPGRAPH_PROPERTY: | 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ) |
| 588 | 0 | if (isAgg) | 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ) |
| 589 | 0 | err = _("aggregate functions are not allowed in property definition expressions"); | 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ) |
| 590 | - | else | 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ) |
| 591 | 0 | err = _("grouping operations are not allowed in property definition expressions"); | 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ) |
| 592 | - | 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ) | |
| 593 | - | break; | 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ) |
| 594 | - | 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ) | |
| 595 | - | /* | - |
| 596 | - | * There is intentionally no default: case here, so that the | - |
| 597 | - | * compiler will warn if we add a new ParseExprKind without | - |
| 598 | - | * extending this switch. If we do see an unrecognized value at | - |
| 599 | - | * runtime, the behavior will be the same as for EXPR_KIND_OTHER, | - |
| 600 | - | * which is sane anyway. | - |
| 601 | - | */ | - |
| 602 | - | } | - |
| 603 | - | - | |
| 604 | - | if (err) | - |
| 605 | - | ereport(ERROR, | - |
| 606 | - | (errcode(ERRCODE_GROUPING_ERROR), | - |
| 607 | - | errmsg_internal("%s", err), | - |
| 608 | - | parser_errposition(pstate, location))); | - |
| 609 | - | - | |
| 610 | - | if (errkind) | - |
| 611 | - | { | - |
| 612 | - | if (isAgg) | - |
| 613 | - | /* translator: %s is name of a SQL construct, eg GROUP BY */ | - |
| 614 | - | err = _("aggregate functions are not allowed in %s"); | - |
| 615 | - | else | - |
| 616 | - | /* translator: %s is name of a SQL construct, eg GROUP BY */ | - |
| 617 | - | err = _("grouping operations are not allowed in %s"); | - |
| 618 | - | - | |
| 619 | - | ereport(ERROR, | - |
| 620 | - | (errcode(ERRCODE_GROUPING_ERROR), | - |
| 621 | - | errmsg_internal(err, | - |
| 622 | - | ParseExprKindName(pstate->p_expr_kind)), | - |
| 623 | - | parser_errposition(pstate, location))); | - |
| 624 | - | } | - |
| 625 | - | } | - |
| Line | Hits | Source | Commit |
|---|---|---|---|
| 886 | - | transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc, | - |
| 887 | - | WindowDef *windef) | - |
| 888 | - | { | - |
| 889 | - | const char *err; | - |
| 890 | - | bool errkind; | - |
| 891 | - | - | |
| 892 | - | /* | - |
| 893 | - | * A window function call can't contain another one (but aggs are OK). XXX | - |
| 894 | - | * is this required by spec, or just an unimplemented feature? | - |
| 895 | - | * | - |
| 896 | - | * Note: we don't need to check the filter expression here, because the | - |
| 897 | - | * context checks done below and in transformAggregateCall would have | - |
| 898 | - | * already rejected any window funcs or aggs within the filter. | - |
| 899 | - | */ | - |
| 900 | - | if (pstate->p_hasWindowFuncs && | - |
| 901 | - | contain_windowfuncs((Node *) wfunc->args)) | - |
| 902 | - | ereport(ERROR, | - |
| 903 | - | (errcode(ERRCODE_WINDOWING_ERROR), | - |
| 904 | - | errmsg("window function calls cannot be nested"), | - |
| 905 | - | parser_errposition(pstate, | - |
| 906 | - | locate_windowfunc((Node *) wfunc->args)))); | - |
| 907 | - | - | |
| 908 | - | /* | - |
| 909 | - | * Check to see if the window function is in an invalid place within the | - |
| 910 | - | * query. | - |
| 911 | - | * | - |
| 912 | - | * For brevity we support two schemes for reporting an error here: set | - |
| 913 | - | * "err" to a custom message, or set "errkind" true if the error context | - |
| 914 | - | * is sufficiently identified by what ParseExprKindName will return, *and* | - |
| 915 | - | * what it will return is just a SQL keyword. (Otherwise, use a custom | - |
| 916 | - | * message to avoid creating translation problems.) | - |
| 917 | - | */ | - |
| 918 | - | err = NULL; | - |
| 919 | - | errkind = false; | - |
| 920 | - | switch (pstate->p_expr_kind) | - |
| 921 | - | { | - |
| 922 | - | case EXPR_KIND_NONE: | - |
| 923 | - | Assert(false); /* can't happen */ | - |
| 924 | - | break; | - |
| 925 | - | case EXPR_KIND_OTHER: | - |
| 926 | - | /* Accept window func here; caller must throw error if wanted */ | - |
| 927 | - | break; | - |
| 928 | - | case EXPR_KIND_JOIN_ON: | - |
| 929 | - | case EXPR_KIND_JOIN_USING: | - |
| 930 | - | err = _("window functions are not allowed in JOIN conditions"); | - |
| 931 | - | break; | - |
| 932 | - | case EXPR_KIND_FROM_SUBSELECT: | - |
| 933 | - | /* can't get here, but just in case, throw an error */ | - |
| 934 | - | errkind = true; | - |
| 935 | - | break; | - |
| 936 | - | case EXPR_KIND_FROM_FUNCTION: | - |
| 937 | - | err = _("window functions are not allowed in functions in FROM"); | - |
| 938 | - | break; | - |
| 939 | - | case EXPR_KIND_WHERE: | - |
| 940 | - | errkind = true; | - |
| 941 | - | break; | - |
| 942 | - | case EXPR_KIND_POLICY: | - |
| 943 | - | err = _("window functions are not allowed in policy expressions"); | - |
| 944 | - | break; | - |
| 945 | - | case EXPR_KIND_HAVING: | - |
| 946 | - | errkind = true; | - |
| 947 | - | break; | - |
| 948 | - | case EXPR_KIND_FILTER: | - |
| 949 | - | errkind = true; | - |
| 950 | - | break; | - |
| 951 | - | case EXPR_KIND_WINDOW_PARTITION: | - |
| 952 | - | case EXPR_KIND_WINDOW_ORDER: | - |
| 953 | - | case EXPR_KIND_WINDOW_FRAME_RANGE: | - |
| 954 | - | case EXPR_KIND_WINDOW_FRAME_ROWS: | - |
| 955 | - | case EXPR_KIND_WINDOW_FRAME_GROUPS: | - |
| 956 | - | err = _("window functions are not allowed in window definitions"); | - |
| 957 | - | break; | - |
| 958 | - | case EXPR_KIND_SELECT_TARGET: | - |
| 959 | - | /* okay */ | - |
| 960 | - | break; | - |
| 961 | - | case EXPR_KIND_INSERT_TARGET: | - |
| 962 | - | case EXPR_KIND_UPDATE_SOURCE: | - |
| 963 | - | case EXPR_KIND_UPDATE_TARGET: | - |
| 964 | - | errkind = true; | - |
| 965 | - | break; | - |
| 966 | - | case EXPR_KIND_MERGE_WHEN: | - |
| 967 | - | err = _("window functions are not allowed in MERGE WHEN conditions"); | - |
| 968 | - | break; | - |
| 969 | - | case EXPR_KIND_GROUP_BY: | - |
| 970 | - | errkind = true; | - |
| 971 | - | break; | - |
| 972 | - | case EXPR_KIND_ORDER_BY: | - |
| 973 | - | /* okay */ | - |
| 974 | - | break; | - |
| 975 | - | case EXPR_KIND_DISTINCT_ON: | - |
| 976 | - | /* okay */ | - |
| 977 | - | break; | - |
| 978 | - | case EXPR_KIND_LIMIT: | - |
| 979 | - | case EXPR_KIND_OFFSET: | - |
| 980 | - | errkind = true; | - |
| 981 | - | break; | - |
| 982 | - | case EXPR_KIND_RETURNING: | - |
| 983 | - | case EXPR_KIND_MERGE_RETURNING: | - |
| 984 | - | errkind = true; | - |
| 985 | - | break; | - |
| 986 | - | case EXPR_KIND_VALUES: | - |
| 987 | - | case EXPR_KIND_VALUES_SINGLE: | - |
| 988 | - | errkind = true; | - |
| 989 | - | break; | - |
| 990 | - | case EXPR_KIND_CHECK_CONSTRAINT: | - |
| 991 | - | case EXPR_KIND_DOMAIN_CHECK: | - |
| 992 | - | err = _("window functions are not allowed in check constraints"); | - |
| 993 | - | break; | - |
| 994 | - | case EXPR_KIND_COLUMN_DEFAULT: | - |
| 995 | - | case EXPR_KIND_FUNCTION_DEFAULT: | - |
| 996 | - | err = _("window functions are not allowed in DEFAULT expressions"); | - |
| 997 | - | break; | - |
| 998 | - | case EXPR_KIND_INDEX_EXPRESSION: | - |
| 999 | - | err = _("window functions are not allowed in index expressions"); | - |
| 1000 | - | break; | - |
| 1001 | - | case EXPR_KIND_STATS_EXPRESSION: | - |
| 1002 | - | err = _("window functions are not allowed in statistics expressions"); | - |
| 1003 | - | break; | - |
| 1004 | - | case EXPR_KIND_INDEX_PREDICATE: | - |
| 1005 | - | err = _("window functions are not allowed in index predicates"); | - |
| 1006 | - | break; | - |
| 1007 | - | case EXPR_KIND_ALTER_COL_TRANSFORM: | - |
| 1008 | - | err = _("window functions are not allowed in transform expressions"); | - |
| 1009 | - | break; | - |
| 1010 | - | case EXPR_KIND_EXECUTE_PARAMETER: | - |
| 1011 | - | err = _("window functions are not allowed in EXECUTE parameters"); | - |
| 1012 | - | break; | - |
| 1013 | - | case EXPR_KIND_TRIGGER_WHEN: | - |
| 1014 | - | err = _("window functions are not allowed in trigger WHEN conditions"); | - |
| 1015 | - | break; | - |
| 1016 | - | case EXPR_KIND_PARTITION_BOUND: | - |
| 1017 | - | err = _("window functions are not allowed in partition bound"); | - |
| 1018 | - | break; | - |
| 1019 | - | case EXPR_KIND_PARTITION_EXPRESSION: | - |
| 1020 | - | err = _("window functions are not allowed in partition key expressions"); | - |
| 1021 | - | break; | - |
| 1022 | - | case EXPR_KIND_CALL_ARGUMENT: | - |
| 1023 | - | err = _("window functions are not allowed in CALL arguments"); | - |
| 1024 | - | break; | - |
| 1025 | - | case EXPR_KIND_COPY_WHERE: | - |
| 1026 | - | err = _("window functions are not allowed in COPY FROM WHERE conditions"); | - |
| 1027 | - | break; | - |
| 1028 | - | case EXPR_KIND_GENERATED_COLUMN: | - |
| 1029 | - | err = _("window functions are not allowed in column generation expressions"); | - |
| 1030 | - | break; | - |
| 1031 | - | case EXPR_KIND_CYCLE_MARK: | - |
| 1032 | - | errkind = true; | - |
| 1033 | - | break; | - |
| 1034 | 0 | case EXPR_KIND_PROPGRAPH_PROPERTY: | 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ) |
| 1035 | 0 | err = _("window functions are not allowed in property definition expressions"); | 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ) |
| 1036 | 0 | break; | 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ) |
| 1037 | - | - | |
| 1038 | - | /* | - |
| 1039 | - | * There is intentionally no default: case here, so that the | - |
| 1040 | - | * compiler will warn if we add a new ParseExprKind without | - |
| 1041 | - | * extending this switch. If we do see an unrecognized value at | - |
| 1042 | - | * runtime, the behavior will be the same as for EXPR_KIND_OTHER, | - |
| 1043 | - | * which is sane anyway. | - |
| 1044 | - | */ | - |
| 1045 | - | } | - |
| 1046 | - | if (err) | - |
| 1047 | - | ereport(ERROR, | - |
| 1048 | - | (errcode(ERRCODE_WINDOWING_ERROR), | - |
| 1049 | - | errmsg_internal("%s", err), | - |
| 1050 | - | parser_errposition(pstate, wfunc->location))); | - |
| 1051 | - | if (errkind) | - |
| 1052 | - | ereport(ERROR, | - |
| 1053 | - | (errcode(ERRCODE_WINDOWING_ERROR), | - |
| 1054 | - | /* translator: %s is name of a SQL construct, eg GROUP BY */ | - |
| 1055 | - | errmsg("window functions are not allowed in %s", | - |
| 1056 | - | ParseExprKindName(pstate->p_expr_kind)), | - |
| 1057 | - | parser_errposition(pstate, wfunc->location))); | - |
| 1058 | - | - | |
| 1059 | - | /* | - |
| 1060 | - | * If the OVER clause just specifies a window name, find that WINDOW | - |
| 1061 | - | * clause (which had better be present). Otherwise, try to match all the | - |
| 1062 | - | * properties of the OVER clause, and make a new entry in the p_windowdefs | - |
| 1063 | - | * list if no luck. | - |
| 1064 | - | */ | - |
| 1065 | - | if (windef->name) | - |
| 1066 | - | { | - |
| 1067 | - | Index winref = 0; | - |
| 1068 | - | ListCell *lc; | - |
| 1069 | - | - | |
| 1070 | - | Assert(windef->refname == NULL && | - |
| 1071 | - | windef->partitionClause == NIL && | - |
| 1072 | - | windef->orderClause == NIL && | - |
| 1073 | - | windef->frameOptions == FRAMEOPTION_DEFAULTS); | - |
| 1074 | - | - | |
| 1075 | - | foreach(lc, pstate->p_windowdefs) | - |
| 1076 | - | { | - |
| 1077 | - | WindowDef *refwin = (WindowDef *) lfirst(lc); | - |
| 1078 | - | - | |
| 1079 | - | winref++; | - |
| 1080 | - | if (refwin->name && strcmp(refwin->name, windef->name) == 0) | - |
| 1081 | - | { | - |
| 1082 | - | wfunc->winref = winref; | - |
| 1083 | - | break; | - |
| 1084 | - | } | - |
| 1085 | - | } | - |
| 1086 | - | if (lc == NULL) /* didn't find it? */ | - |
| 1087 | - | ereport(ERROR, | - |
| 1088 | - | (errcode(ERRCODE_UNDEFINED_OBJECT), | - |
| 1089 | - | errmsg("window \"%s\" does not exist", windef->name), | - |
| 1090 | - | parser_errposition(pstate, windef->location))); | - |
| 1091 | - | } | - |
| 1092 | - | else | - |
| 1093 | - | { | - |
| 1094 | - | Index winref = 0; | - |
| 1095 | - | ListCell *lc; | - |
| 1096 | - | - | |
| 1097 | - | foreach(lc, pstate->p_windowdefs) | - |
| 1098 | - | { | - |
| 1099 | - | WindowDef *refwin = (WindowDef *) lfirst(lc); | - |
| 1100 | - | - | |
| 1101 | - | winref++; | - |
| 1102 | - | if (refwin->refname && windef->refname && | - |
| 1103 | - | strcmp(refwin->refname, windef->refname) == 0) | - |
| 1104 | - | /* matched on refname */ ; | - |
| 1105 | - | else if (!refwin->refname && !windef->refname) | - |
| 1106 | - | /* matched, no refname */ ; | - |
| 1107 | - | else | - |
| 1108 | - | continue; | - |
| 1109 | - | - | |
| 1110 | - | /* | - |
| 1111 | - | * Also see similar de-duplication code in optimize_window_clauses | - |
| 1112 | - | */ | - |
| 1113 | - | if (equal(refwin->partitionClause, windef->partitionClause) && | - |
| 1114 | - | equal(refwin->orderClause, windef->orderClause) && | - |
| 1115 | - | refwin->frameOptions == windef->frameOptions && | - |
| 1116 | - | equal(refwin->startOffset, windef->startOffset) && | - |
| 1117 | - | equal(refwin->endOffset, windef->endOffset)) | - |
| 1118 | - | { | - |
| 1119 | - | /* found a duplicate window specification */ | - |
| 1120 | - | wfunc->winref = winref; | - |
| 1121 | - | break; | - |
| 1122 | - | } | - |
| 1123 | - | } | - |
| 1124 | - | if (lc == NULL) /* didn't find it? */ | - |
| 1125 | - | { | - |
| 1126 | - | pstate->p_windowdefs = lappend(pstate->p_windowdefs, windef); | - |
| 1127 | - | wfunc->winref = list_length(pstate->p_windowdefs); | - |
| 1128 | - | } | - |
| 1129 | - | } | - |
| 1130 | - | - | |
| 1131 | - | pstate->p_hasWindowFuncs = true; | - |
| 1132 | - | } | - |