简体   繁体   English

如何在PostgreSQL中复制函数

[英]How to copy function in PostgreSQL

I want to write sqitch deploy script to create new version of trigger. 我想编写sqitch部署脚本来创建新版本的触发器。 To ensure that revert script will revert function to previous version, I'd like to make a backup of this function. 为了确保还原脚本将函数还原到以前的版本,我想备份此函数。 Is there any way to copy (RENAME TO is not working!) trigger function with new name? 有没有办法复制(RENAME TO无效!)触发功能的新名称?

RENAME TO should work. 重命名应该工作。 Are you forgetting parentheses or including them on the other side? 你忘了括号还是把它们包括在另一边?

Parentheses with alter table rename are a little tricky: 使用alter table rename的括号有点棘手:

postgres=# create function test() returns bool language sql as $$ select true; $$;
CREATE FUNCTION
postgres=# alter function test() rename to old_test();
ERROR:  syntax error at or near "("
LINE 1: alter function test() rename to old_test();
                                                ^
postgres=# alter function test() rename to old_test;
ALTER FUNCTION

If that is not enough, then you could DO and EXECUTE the output of pg_get_functiondef after parsing and renaming it: 如果这还不够,那么你可以DOEXECUTE解析和重命名后pg_get_functiondef的输出:

select * from pg_get_functiondef('old_test'::regproc);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM