【发布时间】:2017-03-21 07:43:43
【问题描述】:
在 PL/pgSQL 上执行和执行有什么区别?
来自手册:
有时对表达式或 SELECT 查询求值但丢弃结果很有用,例如在调用具有副作用但没有有用结果值的函数时。要在 PL/pgSQL 中执行此操作,请使用 PERFORM 语句。
但是,当我尝试这样的事情时:
perform 'create table foo as (select 1)';
什么都没有发生。虽然这个查询应该有副作用(建表),结果可以丢弃。
我认为我做对了 1 件事:为了运行我可以使用 perform 的功能:
perform pg_temp.addInheritance(foo);
【问题讨论】:
-
perform替换select。是选择忽略返回,你不能select 'create table foo as (select 1)'; -
也就是说,它不能对数据库做任何改变?
-
可以,
select可以。不多不少。例如select pg_create_restore_point('change to db');或 select 1 from dblink_exec('local', 'create table...') as (i int)` 左右
标签: postgresql plpgsql