1

I am confused about the passing process of the parameter from functions created in 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;

I have modified some, there is no parameters errors but it still does not work. when I tested it with

select * 
from test1('ECO%', 8)

error: function returns two columns.

Is there any thing wrong with the type? How can I fix it?.

3

1 Answer 1

1

As the message says you are returning two columns. Return a composite type instead:

return next (
    count(v1.code) as pattern_number, count(v2.code) as uoc_number
)::IncorrectRecord
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.