Reputation: 4661
I want to pass the result of a subselect to a function
Say I've got an existing function that returns boolean
function report_can_edit
which takes a report
row type. I want to call this from another function which is passed an id
for a report
( just a silly example to illustrate what I'm trying to do )
create or replace function report_can_edit(report report) returns boolean as $$
select true; -- Imagine this does some complicated stuff
$$ language sql stable;
create or replace function task_edit(task_report_id int) returns boolean as $$
select report_can_edit((select * from report where id = task_report_id))
$$ language sql stable;
This gives
ERROR: subquery must return only one column
Do I have to switch to plpgsql and select into a decared row type first? or is there a way to do this with an sql
type function?
Upvotes: 0
Views: 144
Reputation: 121754
Try:
create or replace function task_edit(task_report_id int)
returns boolean as $$
select report_can_edit((select report from report where id = task_report_id))
$$ language sql stable;
Upvotes: 1