code:
schema = [{"name": "fb_table_1", "dimension": "department", "metrics": ["headcount"]},
{"name": "fb_table_2", "dimension": "area", "metrics": ["sale"]},
{"name": "fb_table_3", "dimension": "product", "metrics": ["quantity", "revenue"]}]
template = f"select date, '{table["dimension"]}', {table['dimension']}, '{metric}', {metric} from {table['name']}"
sql_2 = " union ".join([template for table in schema for metric in table["metrics"]])
print(sql_2)
get following errors:
template = f"select date, '{table["dimension"]}', {table['dimension']}, '{metric}', {metric} from {table['name']}"
^
SyntaxError: invalid syntax
Is that caused by the nested single/double quotations?
update: when I change to
template = f"select date, '{table['dimension']}', {table['dimension']}, '{metric}', {metric} from {table['name']}"
I get another error:
NameError: name 'table' is not defined
what's the cause of this one?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…