Объявление переменной - PullRequest
0 голосов
/ 06 мая 2019

Я хочу назначить переменную в нижеприведенном виде в plpgsql.

declare file_name varchar;
    i_str varchar(500);
    start_date date;
 end_date date;

    select  v_file_name=concat('tmp_',replace(replace(rd.file_name,'.csv',''),'-','_'))  as files  
            ,rd.filter_2 = i_str
    from reports as rd 
    where rd.id = rep_id 
          and rd.status=0;

    if ( file_name) is not null
    begin

    update report_downloads set status=1 where id =rep_id and status=0

    end;
else 
    begin
    update report_downloads  set status=3 where id =rep_id and status=1
    end;

Но может увидеть следующую проблему:

КОНТЕКСТ: недопустимый тип Состояние SQL: 42601 Символ: 202

1 Ответ

0 голосов
/ 09 мая 2019

Если вы все еще застряли в этом вопросе:

DO $$
DECLARE
   -- assign your variables here
   -- [variable_name] [type];
BEGIN
   -- do some code
   -- SELECT 1 INTO [variable] FROM ...
   -- [variable] := [value]
END;
$$ LANGUAGE plpgsql;

Надеюсь, это поможет

...