I have SQL query as a string:
SELECT DISTINCT a, b AS value FROM ${source} WHERE b IN (${string}) AND slice_start >= ${date} AND slice_start <= ${date1};
And I need to replace the parameters using dictionary , that comes from JSON file looking like this:
my_dict = {"source": "table", "string": "abc", "date": "2020-01-01", "date1": "2020-01-02"}
I am confused how to replace every string that starts with $ and how to attach " (but not on source) at the end and at the begging of every parameter, so the SQL query can be executed later. This is where I am now:
for k, v in target_groups_queries.items():
if isinstance(v, dict):
for k1, v1 in v.items():
queries = v1['sql'].split()
final_string = ' '.join(str(my_dict.get(word, word)) for word in queries)
print(final_string)
else:
pass
$s beforehand?