Reputation: 1561
I am trying to pass a list of columns into a SQL query in Python. This just returns back the list but not the actual columns as shown:
cols = ["col_a","col_b","col_c"]
query = f"""select '{cols}' from table"""
Current Output : f"""select '["col_a","col_b","col_c"]' from table"""
Expected output: f"""select col_a, col_b, col_c from table"""
Upvotes: 1
Views: 2296
Reputation: 4837
You want to do a join
of the list:
query = f"""select {", ".join(cols)} from table"""
Upvotes: 7