0

I have a simple Postgres function:

CREATE OR REPLACE FUNCTION public.drivers_have_unsatisfied_documents()
 RETURNS driver_expiring_documents
AS $function$
DECLARE
    unsatified_documents driver_expiring_documents;
    expiring_doc driver_expiring_documents%rowtype;
    expiring_doc_driver_ids text[];
    expired_doc_driver_ids text[];
    expiring_date date;
    driver_id_arg text;
BEGIN
    unsatified_documents := array(
    select expiration_date, driver_id from all_requirements_driver_documents where expiration_date <= (now() + interval '1 month')::DATE and expiration_date > (now() - interval '7 day')::DATE
    union
    select expiration_date, driver_id from all_requirements_vehicle_documents where expiration_date <= (now() + interval '1 month')::DATE and expiration_date > (now() - interval '7 day')::DATE
    );
    -- Do some more stuff, code intentionally removed ---
    return unsatified_documents;
end;
$function$ stable language 'plpgsql';

This is throws error saying

multiple columns in subquery

Can someone please help me fix it?

5
  • 1
    You cannot put a query that returns multiple columns in an array. Commented Jul 12, 2022 at 20:33
  • What is the driver_expiring_documents type? Commented Jul 12, 2022 at 20:34
  • Duplicate question: stackoverflow.com/questions/23106445/… Commented Jul 12, 2022 at 23:27
  • Does this answer your question? How to return multiple rows from PL/pgSQL function? Commented Jul 12, 2022 at 23:27
  • 1
    Why not use RETURNS setof driver_expiring_documents to return multiple rows with multiple columns? Commented Jul 13, 2022 at 7:42

0

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.