1
我感到困惑的Postgres裏創建的函數參數的傳遞過程:PostgreSQL函數返回多個列
create type IncorrectRecord as (pattern_number integer, uoc_number integer);
create or replace function text1(pattern text, uoc_threshold integer)
returns setof IncorrectRecord
as $$
begin
return next count(v1.code) as pattern_number, count(v2.code) as uoc_number
from (select * from q1_1 where code like pattern) as v1, (select
* from q1_1 where code like pattern and uoc > uoc_threshold) as v2;
return;
end
$$ language plpgsql;
我已經修改了一些,沒有任何參數錯誤,但它仍然無法正常工作。 當我
select *
from test1('ECO%', 8)
error: function returns two columns.
測試它是否有任何一點毛病的類型?我該如何解決它?
'返回IncorrectRecord' - 什麼是'IncorrectRecord'? –
如果您想要檢索一對值,其中第一個是「代碼像模式」的計數,第二個是「代碼像模式和uoc> uoc_threshold」的計數,則使用錯誤的方法。簡而言之,回答你的問題是不可能在DDL中使用參數的。 – Abelisto
這是一種功課嗎?看起來非常類似於:http://stackoverflow.com/questions/43735008/postgresql-functions –