mirror of
https://github.com/postgres/postgres.git
synced 2025-12-12 02:37:31 +03:00
SQL procedures
This adds a new object type "procedure" that is similar to a function but does not have a return type and is invoked by the new CALL statement instead of SELECT or similar. This implementation is aligned with the SQL standard and compatible with or similar to other SQL implementations. This commit adds new commands CALL, CREATE/ALTER/DROP PROCEDURE, as well as ALTER/DROP ROUTINE that can refer to either a function or a procedure (or an aggregate function, as an extension to SQL). There is also support for procedures in various utility commands such as COMMENT and GRANT, as well as support in pg_dump and psql. Support for defining procedures is available in all the languages supplied by the core distribution. While this commit is mainly syntax sugar around existing functionality, future features will rely on having procedures as a separate object type. Reviewed-by: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
This commit is contained in:
41
src/pl/plpython/sql/plpython_call.sql
Normal file
41
src/pl/plpython/sql/plpython_call.sql
Normal file
@@ -0,0 +1,41 @@
|
||||
--
|
||||
-- Tests for procedures / CALL syntax
|
||||
--
|
||||
|
||||
CREATE PROCEDURE test_proc1()
|
||||
LANGUAGE plpythonu
|
||||
AS $$
|
||||
pass
|
||||
$$;
|
||||
|
||||
CALL test_proc1();
|
||||
|
||||
|
||||
-- error: can't return non-None
|
||||
CREATE PROCEDURE test_proc2()
|
||||
LANGUAGE plpythonu
|
||||
AS $$
|
||||
return 5
|
||||
$$;
|
||||
|
||||
CALL test_proc2();
|
||||
|
||||
|
||||
CREATE TABLE test1 (a int);
|
||||
|
||||
CREATE PROCEDURE test_proc3(x int)
|
||||
LANGUAGE plpythonu
|
||||
AS $$
|
||||
plpy.execute("INSERT INTO test1 VALUES (%s)" % x)
|
||||
$$;
|
||||
|
||||
CALL test_proc3(55);
|
||||
|
||||
SELECT * FROM test1;
|
||||
|
||||
|
||||
DROP PROCEDURE test_proc1;
|
||||
DROP PROCEDURE test_proc2;
|
||||
DROP PROCEDURE test_proc3;
|
||||
|
||||
DROP TABLE test1;
|
||||
Reference in New Issue
Block a user