- Notifications
You must be signed in to change notification settings - Fork5k
Commite717a9a
committed
SQL-standard function body
This adds support for writing CREATE FUNCTION and CREATE PROCEDUREstatements for language SQL with a function body that conforms to theSQL standard and is portable to other implementations.Instead of the PostgreSQL-specific AS $$ string literal $$ syntax,this allows writing out the SQL statements making up the bodyunquoted, either as a single statement: CREATE FUNCTION add(a integer, b integer) RETURNS integer LANGUAGE SQL RETURN a + b;or as a block CREATE PROCEDURE insert_data(a integer, b integer) LANGUAGE SQL BEGIN ATOMIC INSERT INTO tbl VALUES (a); INSERT INTO tbl VALUES (b); END;The function body is parsed at function definition time and stored asexpression nodes in a new pg_proc column prosqlbody. So at run time,no further parsing is required.However, this form does not support polymorphic arguments, becausethere is no more parse analysis done at call time.Dependencies between the function and the objects it uses are fullytracked.A new RETURN statement is introduced. This can only be used insidefunction bodies. Internally, it is treated much like a SELECTstatement.psql needs some new intelligence to keep track of function bodyboundaries so that it doesn't send off statements when it seessemicolons that are inside a function body.Tested-by: Jaime Casanova <jcasanov@systemguards.com.ec>Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>Discussion:https://www.postgresql.org/message-id/flat/1c11f1eb-f00c-43b7-799d-2d44132c02d7@2ndquadrant.com1 parent1e55e7d commite717a9a
File tree
37 files changed
+1411
-212
lines changed- doc/src/sgml
- ref
- src
- backend
- catalog
- commands
- executor
- nodes
- optimizer/util
- parser
- tcop
- utils/adt
- bin
- pg_dump
- psql
- fe_utils
- include
- catalog
- commands
- executor
- fe_utils
- nodes
- parser
- tcop
- interfaces/ecpg/preproc
- test/regress
- expected
- sql
37 files changed
+1411
-212
lines changedLines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6002 | 6002 |
| |
6003 | 6003 |
| |
6004 | 6004 |
| |
| 6005 | + | |
| 6006 | + | |
| 6007 | + | |
| 6008 | + | |
| 6009 | + | |
| 6010 | + | |
| 6011 | + | |
| 6012 | + | |
| 6013 | + | |
| 6014 | + | |
6005 | 6015 |
| |
6006 | 6016 |
| |
6007 | 6017 |
| |
|
Lines changed: 113 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
38 | 38 |
| |
39 | 39 |
| |
40 | 40 |
| |
| 41 | + | |
41 | 42 |
| |
42 | 43 |
| |
43 | 44 |
| |
| |||
262 | 263 |
| |
263 | 264 |
| |
264 | 265 |
| |
265 |
| - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
266 | 269 |
| |
267 | 270 |
| |
268 | 271 |
| |
| |||
582 | 585 |
| |
583 | 586 |
| |
584 | 587 |
| |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
585 | 626 |
| |
586 | 627 |
| |
587 | 628 |
| |
| |||
667 | 708 |
| |
668 | 709 |
| |
669 | 710 |
| |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
670 | 720 |
| |
671 | 721 |
| |
672 | 722 |
| |
| |||
797 | 847 |
| |
798 | 848 |
| |
799 | 849 |
| |
800 |
| - | |
801 |
| - | |
802 |
| - | |
803 |
| - | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
804 | 855 |
| |
805 | 856 |
| |
806 | 857 |
| |
807 |
| - | |
808 |
| - | |
809 |
| - | |
810 |
| - | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
811 | 910 |
| |
812 | 911 |
| |
813 | 912 |
| |
814 |
| - | |
815 |
| - | |
816 |
| - | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
817 | 918 |
| |
818 | 919 |
| |
819 | 920 |
| |
|
Lines changed: 56 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
29 | 29 |
| |
30 | 30 |
| |
31 | 31 |
| |
| 32 | + | |
32 | 33 |
| |
33 | 34 |
| |
34 | 35 |
| |
| |||
167 | 168 |
| |
168 | 169 |
| |
169 | 170 |
| |
170 |
| - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
171 | 174 |
| |
172 | 175 |
| |
173 | 176 |
| |
| |||
304 | 307 |
| |
305 | 308 |
| |
306 | 309 |
| |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
307 | 345 |
| |
308 | 346 |
| |
309 | 347 |
| |
| |||
323 | 361 |
| |
324 | 362 |
| |
325 | 363 |
| |
| 364 | + | |
326 | 365 |
| |
327 | 366 |
| |
328 | 367 |
| |
329 | 368 |
| |
330 | 369 |
| |
331 | 370 |
| |
332 | 371 |
| |
333 |
| - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
334 | 384 |
| |
335 | 385 |
| |
| 386 | + | |
336 | 387 |
| |
337 | 388 |
| |
338 | 389 |
| |
339 | 390 |
| |
340 | 391 |
| |
341 | 392 |
| |
342 | 393 |
| |
343 |
| - | |
344 |
| - | |
345 |
| - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
346 | 397 |
| |
347 | 398 |
| |
348 | 399 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
622 | 622 |
| |
623 | 623 |
| |
624 | 624 |
| |
| 625 | + | |
625 | 626 |
| |
626 | 627 |
| |
627 | 628 |
| |
|
0 commit comments
Comments
(0)