0

I need to execute a complex query for testing purposes with params.

How to write a SELECT query which can be executed in DataGrip / PgAdmin with params:

EXECUTE 'SELECT * FROM tenant where id = $1'
   USING 6;
END

(this doesn't work)

and I need to get the same result as from:

SELECT * FROM tenant where id = 6

Thank you

David
  • 825
  • 10
  • 33

1 Answers1

0

Finally found solution, even it's a bit tricky:

DO
$$
    DECLARE
        res RECORD;
    BEGIN
        drop table if exists my_temp_table;

        EXECUTE 'CREATE TEMP TABLE my_temp_table AS
        SELECT * FROM tenant where id = $1'
            USING 3243;

    END
$$;
select * from my_temp_table;
David
  • 825
  • 10
  • 33