I have a postgres function called site_opened_on_date which take as input an id and a date. The function's signature looks like this :
CREATE OR REPLACE FUNCTION recntrek.site_opened_on_date(
site_id bigint,
in_date date DEFAULT (
now(
))::date)
RETURNS SETOF "TABLE(date date, opening_time time without time zone, closing_time time without time zone)"
LANGUAGE 'plpgsql'
COST 5.0
STABLE
ROWS 3.0
AS $function$
I want to apply this function on 7 days. I have tried this:
SELECT (
SELECT t FROM site_opened_on_date(100520000101526, _d) t
)FROM unnest(ARRAY[ now(),
now()+ INTERVAL '1 DAY',
now()+ INTERVAL '2 DAY',
now()+ INTERVAL '3 DAY',
now()+ INTERVAL '4 DAY',
now()+ INTERVAL '5 DAY',
now()+ INTERVAL '6 DAY'
]::DATE[]) _d;
But I get the following error: more than one row returned by a subquery used as an expression This is due to the fact that the site_opened_on_date function can return more than one row for a date. Anyone has an idea of a solution ? I would rather not write a new postgres function, I would prefer to find a way to apply my array to the existing function in a query.
in_date date[]in postgresql.. and call the function likeSELECT site_opened_on_date(100520000101526, ARRAY[ now(), now()+ INTERVAL '1 DAY', now()+ INTERVAL '2 DAY', now()+ INTERVAL '3 DAY', now()+ INTERVAL '4 DAY', now()+ INTERVAL '5 DAY', now()+ INTERVAL '6 DAY' ]::DATE[])