I'm using Postgraphile, which has you create functions that take row sets as arguments. For instance, I have a function that takes a system_versions row set as a parameter:
CREATE OR REPLACE FUNCTION public.system_versions_edition_versions(
system_version system_versions,
system_title character varying DEFAULT NULL::character varying
)
RETURNS SETOF edition_versions
LANGUAGE sql
STABLE STRICT SECURITY DEFINER
AS $function$
SELECT ev.*
FROM public.edition_versions ev
INNER JOIN public.editions e ON ev.edition_id = e.id
INNER JOIN public.systems s ON e.system_id = s.id
INNER JOIN public.system_versions sv ON s.id = sv.system_id
WHERE sv.id = system_version.id
AND (
system_title IS NULL
OR
sv.title = system_title
)
;
$function$
;
Normally these functions are called by Postgraphile, but I need to call this one manually for testing ... and I can't figure out how to provide the parameter.
When I try:
SELECT public.system_versions_edition_versions(public.system_versions);
I get:
ERROR: missing FROM-clause entry for table "public"
LINE 1: select public.system_versions_edition_versions(public.system...
But when I try to SELECT the table ...
SELECT public.system_versions_edition_versions(SELECT * FROM public.
system_versions);
I get:
ERROR: syntax error at or near "select"
LINE 1: select public.system_versions_edition_versions(select * from...
When I have a function with a "row set" parameter, can anyone explain how I provide that parameter?
It looks like
system_versionargument type is row rather than rowset. Otherwisesv.id = system_version.idwould cause an error. Sincepublic.system_versionsis a table thensystem_versionsis its row type, likesystem_versions%rowtypein PL/pgSQL.You can call it using a scalar subquery like this:
or
You may also consider using a lateral join.