'List of parameters for SQL Query in PyCharm

I have 2 schemas and 10 similarly named tables in both. I want to count number of rows in each table and have the result as a single table. One way is to write bunch of unions, but I want more automated way to do it in PyCharm

My query is:

select
    '{schema}' as schema,
    'table_{table_id}' as table,
    count(*)
from {schema}.table_{table_id};

I want to pass list of parameters to schema (schema_1, schema_2) and table_id (range of numbers from 1 to 10) parameters and union all result. Is it possible in PyCharm?



Sources

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

Source: Stack Overflow

Solution Source