Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to insert multiple commands into a prepared statement

The problem is that putting queries together, I got this "error: cannot insert multiple commands into a prepared statement". What can I do?

q1="
    set search_path to care;
    SELECT COALESCE(c.date,a.date,jq.date,jn.date) reportmonth,registration,emailverified,application,submitted,eligible,jqtest,selected,joined
    from      ( SELECT date_trunc('month', createdon)::date as date, count(1) as registration,count(case when emailverified='Yes'then 1 end) as emailverified from contact group by 1)
    full join ( SELECT date_trunc('month', timecreated)::date as date, count(1) as joined from scholars where deleted='FALSE' group by 1 ) jn on jn.date=c.date
    order by 1;"

funnel=dbGetQuery(prod,q1)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You cannot do that.

In your case, a simple solution would be to get rid of the SET statement and run a single SELECT, where you qualify all tables with the schema name.

For other cases, an alternative is to create a PL/pgSQL function with the statements in it:

CREATE FUNCTION mystmt() RETURNS TABLE (date, ...)
LANGUAGE plpgsql
SET search_path = talentcare AS
$$BEGIN
   RETURN SELECT ...;
END;$$;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading