首页 > 解决方案 > 我需要在 postgresql 中使用表名作为变量

问题描述

我创建了一个函数,我需要为不同的表多次调用,但是当尝试使用表名作为函数中的输入变量时,它给了我一个错误。我读到如果使用“执行”语句是可能的,但是我不知道如何应用它

我的代码是:

CREATE OR REPLACE FUNCTION cta_tiempos7 (nomLD text, nomRe text, subst text, out FIM) AS $$

declare
        resta_ok int;
        cie_res int;
        t_abi timestamp;
        t_cie timestamp;
        t_fuera interval;
        t_switc interval;
        tiempos Record; 
        cur_evento Cursor for select  nombre, señal as signal, estampa from subst
                    where nombre in (nomLD, nomRe) and señal in ('Indicacion 52 Cerrado', 'Indicacion 52 abierto');

begin
.
.
.
.
.
end;
$$ language 'plpgsql';

标签: postgresqlcursor

解决方案


推荐阅读