作者
digoal
日期
2021-04-08
标签
PostgreSQL , SQL 标准 , function body
背景
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=e717a9a18b2e34c9c40e5259ad4d31cd7e420750
```
SQL-standard function body
author Peter Eisentraut peter@eisentraut.org
Wed, 7 Apr 2021 19:30:08 +0000 (21:30 +0200)
committer Peter Eisentraut peter@eisentraut.org
Wed, 7 Apr 2021 19:47:55 +0000 (21:47 +0200)
commit e717a9a18b2e34c9c40e5259ad4d31cd7e420750
tree 6eda5b4cf6468d599efc0da4628bec53d35484af tree
parent 1e55e7d1755cefbb44982fbacc7da461fa8684e6 commit | diff
SQL-standard function body
This adds support for writing CREATE FUNCTION and CREATE PROCEDURE
statements for language SQL with a function body that conforms to the
SQL 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 body
unquoted, 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 as
expression 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, because
there is no more parse analysis done at call time.
Dependencies between the function and the objects it uses are fully
tracked.
A new RETURN statement is introduced. This can only be used inside
function bodies. Internally, it is treated much like a SELECT
statement.
psql needs some new intelligence to keep track of function body
boundaries so that it doesn't send off statements when it sees
semicolons 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.com
```
PostgreSQL 许愿链接
您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.