Let's say I have the following str:
sql = "SELECT c1, c2 FROM {{ table1 }} LEFT JOIN {{ table2 }}"
And I want to render it without specifying the values of table1
and table2
, and they should have a default value specified by me i.e "table". So the rendered str would be:
rendered_sql = "SELECT c1, c2 FROM table LEFT JOIN table"
I need to render hundreds of similar strings, and each of them could have an arbitrary number of variables, with no shared names between them, so I can't do things like {{ table1 or 'table' }}
or {{ table1|default('foo') }}
because it would involve a lot of manual work for modifying all the strings. The value can't be a blank string either.
In conclusion, I would want for the following strings:
str_1 = "SELECT c1, c2 FROM {{ table1 }} LEFT JOIN {{ table2 }}"
str_2 = "SELECT c3, c4 FROM {{ table4 }} LEFT JOIN {{ table7 }} INNER JOIN {{ prior_table0 }}"
To be rendered like:
"SELECT c1, c2 FROM default_value LEFT JOIN default_value"
"SELECT c3, c4 FROM default_value LEFT JOIN default_value INNER JOIN default_value"
Because none of the variables is defined, and I dont want to manually add the default value for each of the variables
Is this possible? Thanks