git.postgresql.org Git - postgresql.git/commit

git projects / postgresql.git / commit
? search:
summary | shortlog | log | commit | commitdiff | tree
(parent: 1e55e7d) | patch
SQL-standard function body
Wed, 7 Apr 2021 19:30:08 +0000 (21:30 +0200)
Wed, 7 Apr 2021 19:47:55 +0000 (21:47 +0200)
commit e717a9a18b2e34c9c40e5259ad4d31cd7e420750
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
37 files changed:
doc/src/sgml/catalogs.sgml diff | blob | blame | history
doc/src/sgml/ref/create_function.sgml diff | blob | blame | history
doc/src/sgml/ref/create_procedure.sgml diff | blob | blame | history
src/backend/catalog/pg_aggregate.c diff | blob | blame | history
src/backend/catalog/pg_proc.c diff | blob | blame | history
src/backend/commands/aggregatecmds.c diff | blob | blame | history
src/backend/commands/functioncmds.c diff | blob | blame | history
src/backend/commands/typecmds.c diff | blob | blame | history
src/backend/executor/functions.c diff | blob | blame | history
src/backend/nodes/copyfuncs.c diff | blob | blame | history
src/backend/nodes/equalfuncs.c diff | blob | blame | history
src/backend/nodes/outfuncs.c diff | blob | blame | history
src/backend/nodes/readfuncs.c diff | blob | blame | history
src/backend/optimizer/util/clauses.c diff | blob | blame | history
src/backend/parser/analyze.c diff | blob | blame | history
src/backend/parser/gram.y diff | blob | blame | history
src/backend/tcop/postgres.c diff | blob | blame | history
src/backend/utils/adt/ruleutils.c diff | blob | blame | history
src/bin/pg_dump/pg_dump.c diff | blob | blame | history
src/bin/psql/describe.c diff | blob | blame | history
src/fe_utils/psqlscan.l diff | blob | blame | history
src/include/catalog/catversion.h diff | blob | blame | history
src/include/catalog/pg_proc.dat diff | blob | blame | history
src/include/catalog/pg_proc.h diff | blob | blame | history
src/include/commands/defrem.h diff | blob | blame | history
src/include/executor/functions.h diff | blob | blame | history
src/include/fe_utils/psqlscan_int.h diff | blob | blame | history
src/include/nodes/nodes.h diff | blob | blame | history
src/include/nodes/parsenodes.h diff | blob | blame | history
src/include/parser/kwlist.h diff | blob | blame | history
src/include/tcop/tcopprot.h diff | blob | blame | history
src/interfaces/ecpg/preproc/ecpg.addons diff | blob | blame | history
src/interfaces/ecpg/preproc/ecpg.trailer diff | blob | blame | history
src/test/regress/expected/create_function_3.out diff | blob | blame | history
src/test/regress/expected/create_procedure.out diff | blob | blame | history
src/test/regress/sql/create_function_3.sql diff | blob | blame | history
src/test/regress/sql/create_procedure.sql diff | blob | blame | history
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /