2017-07-11 30 views
0

我已經搜索了互聯網,找不到任何有關如何使用EXECUTE INTO的信息或示例,包括何時該stamement可能不會返回任何內容。 EXECUTE的執行INTO以接受NULL值

我收到錯誤

查詢字符串參數爲空

我一直在使用IF EXISTS嘗試() 創建一個包含一個計數和things.At這點的整體筏聲明我覺得我可以繞着圈子走。令人沮喪!

有沒有這樣做的默認方法?

+0

請** [編輯] **你的問題,並添加* * PL/pgSQL函數的真實**代碼。 [**格式化文本**](http://stackoverflow.com/help/formatting)請,[**沒有屏幕截圖**](http://meta.stackoverflow.com/questions/285551/why-may -i-不上傳圖像-的代碼上那麼當灰化-A-問題/ 285557#285557)。 ** [**]您的問題 - 請勿**在論壇中發佈代碼或其他信息。 –

回答

1

這裏execute format('select 1 where false') into t會把沒什麼T,所以後來execute t會給

ERROR: query string argument of EXECUTE is null

這麼簡單COALESCE將幫助:

t=# do $$ 
declare t text; 
begin 
execute format('select 1 where %L',false) into t; 
execute coalesce(t,'select now()') into t; 
raise '%',t; 
end; 
$$ 
; 
ERROR: 2017-07-11 16:11:03.149521+00 
Time: 0.349 ms 
相關問題