小编ASA*_*ASA的帖子

声明变量set = select

这可能听起来像一个非常愚蠢的问题,但我如何声明一个用于PostgreSQL 9.3查询的变量?

CREATE or replace FUNCTION public.test()
  returns int4
AS
$BODY$
DECLARE    
    cod_process bigint :=30001;
    cod_instance bigint ;
    utc_log timestamp without time zone := localtimestamp;
    cod_log_type varchar(100) :='information ';
    txt_log_text varchar(100):= 'start process';
    txt_log varchar(100):= txt_log_text||'_'||cod_process;
    set cod_instance= select max(cod_instance) as cod_instance from public.instance where public.instance.cod_process=cod_process;    
BEGIN  
    INSERT INTO public.log (cod_process, cod_instance, utc_log,cod_log_type,txt_log)
    VALUES (cod_process, cod_instance, utc_log,cod_log_type,txt_log );
    RETURN 11;
END;
$BODY$ LANGUAGE 'plpgsql';
Run Code Online (Sandbox Code Playgroud)
ERROR: type "cod_instance" does not exist
SQL state: 42704
Character: 383
Run Code Online (Sandbox Code Playgroud)

postgresql variables set plpgsql declare

12
推荐指数
2
解决办法
4万
查看次数

标签 统计

declare ×1

plpgsql ×1

postgresql ×1

set ×1

variables ×1