【发布时间】:2017-05-02 20:09:37
【问题描述】:
我对 Postgres 中创建的函数的参数传递过程感到困惑:
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)
错误:函数返回两列。
类型有什么问题吗?我该如何解决?
【问题讨论】:
-
returns IncorrectRecord- 什么是IncorrectRecord? -
如果你想检索这对值,其中第一个是
code like pattern的计数,第二个是code like pattern and uoc > uoc_threshold的计数 - 你使用了错误的方法。回答你的问题,简而言之,在DDL中使用参数是不可能的。 -
这是作业吗?看起来非常类似于:stackoverflow.com/questions/43735008/postgresql-functions
标签: postgresql plpgsql