forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit40c24bf
committed
Improve our ability to regurgitate SQL-syntax function calls.
The SQL spec calls out nonstandard syntax for certain function calls,for example substring() with numeric position info is supposed to bespelled "SUBSTRING(string FROM start FOR count)". We accept manyof these things, but up to now would not print them in the same format,instead simplifying down to "substring"(string, start, count).That's long annoyed me because it creates an interoperabilityproblem: we're gratuitously injecting Postgres-specific syntax intowhat might otherwise be a perfectly spec-compliant view definition.However, the real reason for addressing it right now is to supporta planned change in the semantics of EXTRACT() a/k/a date_part().When we switch that to returning numeric, we'll have the parsertranslate EXTRACT() to some new function name (might as well be"extract" if you ask me) and then teach ruleutils.c to reverse-listthat per SQL spec. In this way existing calls to date_part() willcontinue to have the old semantics.To implement this, invent a new CoercionForm value COERCE_SQL_SYNTAX,and make the parser insert that rather than COERCE_EXPLICIT_CALL whenthe input has SQL-spec decoration. (But if the input has the form ofa plain function call, continue to mark it COERCE_EXPLICIT_CALL, evenif it's calling one of these functions.) Then ruleutils.c recognizesCOERCE_SQL_SYNTAX as a cue to emit SQL call syntax. It can knowwhich decoration to emit using hard-wired knowledge about thefunctions that could be called this way. (While this solution isn'textensible without manual additions, neither is the grammar, so thisdoesn't seem unmaintainable.) Notice that this solution willreverse-list a function call with SQL decoration only if it wasentered that way; so dump-and-reload will not by itself produce anychanges in the appearance of views.This requires adding a CoercionForm field to struct FuncCall.(I couldn't resist the temptation to rearrange that struct'sfield order a tad while I was at it.) FuncCall doesn't appearin stored rules, so that change isn't a reason for a catversionbump, but I did one anyway because the new enum value forCoercionForm fields could confuse old backend code.Possible future work:* Perhaps CoercionForm should now be renamed to DisplayForm,or something like that, to reflect its more general meaning.This'd require touching a couple hundred places, so it's notclear it's worth the code churn.* The SQLValueFunction node type, which was invented partly forthe same goal of improving SQL-compatibility of view output,could perhaps be replaced with regular function calls markedwith COERCE_SQL_SYNTAX. It's unclear if this would be a netcode savings, however.Discussion:https://postgr.es/m/42b73d2d-da12-ba9f-570a-420e0cce19d9@phystech.edu1 parentf21636e commit40c24bf
File tree
17 files changed
+480
-71
lines changed- src
- backend
- nodes
- parser
- utils/adt
- include
- catalog
- nodes
- test
- modules/test_rls_hooks
- regress
- expected
- sql
17 files changed
+480
-71
lines changedLines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2682 | 2682 |
| |
2683 | 2683 |
| |
2684 | 2684 |
| |
| 2685 | + | |
2685 | 2686 |
| |
2686 | 2687 |
| |
2687 | 2688 |
| |
2688 | 2689 |
| |
2689 |
| - | |
| 2690 | + | |
2690 | 2691 |
| |
2691 | 2692 |
| |
2692 | 2693 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2369 | 2369 |
| |
2370 | 2370 |
| |
2371 | 2371 |
| |
| 2372 | + | |
2372 | 2373 |
| |
2373 | 2374 |
| |
2374 | 2375 |
| |
2375 | 2376 |
| |
2376 |
| - | |
| 2377 | + | |
2377 | 2378 |
| |
2378 | 2379 |
| |
2379 | 2380 |
| |
|
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
582 | 582 |
| |
583 | 583 |
| |
584 | 584 |
| |
585 |
| - | |
| 585 | + | |
586 | 586 |
| |
587 | 587 |
| |
588 | 588 |
| |
589 | 589 |
| |
590 | 590 |
| |
591 | 591 |
| |
592 | 592 |
| |
| 593 | + | |
593 | 594 |
| |
594 | 595 |
| |
595 | 596 |
| |
596 | 597 |
| |
597 |
| - | |
| 598 | + | |
598 | 599 |
| |
599 | 600 |
| |
600 | 601 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2765 | 2765 |
| |
2766 | 2766 |
| |
2767 | 2767 |
| |
| 2768 | + | |
2768 | 2769 |
| |
2769 | 2770 |
| |
2770 | 2771 |
| |
2771 | 2772 |
| |
2772 |
| - | |
| 2773 | + | |
2773 | 2774 |
| |
2774 | 2775 |
| |
2775 | 2776 |
| |
|
0 commit comments
Comments
(0)