如何使用PostgreSQL输出过程的ddl



如何编写将输出sql过程的DDLsql查询(使用PostgreSQL(。

例如,我有DDL:的程序

CREATE OR REPLACE FUNCTION entertainment.test_proc()
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS $$                                                                                                                                                   
declare
sender int,
receiver int, 
amount dec
begin
-- subtracting the amount from the sender's account 
update accounts 
set balance = balance - amount 
where id = sender;
-- adding the amount to the receiver's account
update accounts 
set balance = balance + amount 
where id = receiver;
end
$$
EXECUTE ON ANY;

我想在变量中编写DDL,以便在我的sql解析器中使用它,因为我想自动化这个过程。

如果有任何建议,我将不胜感激!

在routine_definition中,您将找到进程的ddl:

SELECT
routine_schema,
routine_name,
routine_definition
FROM information_schema.routines
WHERE routine_type = 'PROCEDURE';

最新更新