我在 postgresql 中創建函式來更新表。當我運行單個函式時它作業正常,但我在函式內使用相同的查詢它不會作業。
update house1 SET calendar= 'H'||' '||house_num::text||' '||left(to_char(sdate, 'Mon'),2) ||' to ' || to_char(sdate, 'DD') ||to_char(rdate, 'Mon-DD') where id=1
內部函式我寫了以下查詢
begin
execute
'UPDATE house1 SET calendar = '
||quote_nullable( 'H')||' '||house_num||' '||left(to_char(sdate, 'Mon'),2) ||' to ' || to_char(sdate, 'DD') ||to_char(rdate, 'Mon-DD')
|| ' WHERE' || 'stage'
'>=' || quote_nullable(0) ;
END
它產生以下錯誤
錯誤:列“house_num”不存在。
請幫我
uj5u.com熱心網友回復:
為什么要execute在函式中使用陳述句?
可以直接在函式中使用update陳述句(execute如果需要構建動態查詢,使用陳述句時)
create or replace function function_name()
returns void
language plpgsql
as
$$
begin
update house1 SET calendar=
'H'||' '||house_num::text||' '||left(to_char(sdate, 'Mon'),2) ||' to ' || to_char(sdate, 'DD') ||to_char(rdate, 'Mon-DD')
where stage >= 0;
end;
$$;
select function_name();
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/406871.html
標籤:
