'How to execute SELECT with params in DataGrip / PgAdmin etc..?

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



Solution 1:[1]

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;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David