0

I want to use a variable in the Select Query but it give me a fail. Someone can guide me how to insert this variable in my SQL query ?


project = test

# Our SQL Query
Query_1 = """
SELECT * FROM project.dataplex_dq.dq-results`
"""
# labelling our query job
query_job_1 = client.query(Query_1)

# results as a dataframe
Table = query_job_1.result().to_dataframe()
4
  • 1
    What variable? How does it fail? Commented Aug 17, 2022 at 10:48
  • Basically If I use for instance SELECT * FROM test.dataplex_dq.dq-results` it will work it will display me information. But in the future it is possible the location will become test2.dataplex_dq.dq-results` So I want to make my code generic and not to have to change it everytime. I want to store this info in a variable and use it in the query then Commented Aug 17, 2022 at 10:53
  • 1
    MYSQL does not do variable substitution for objects (eg tables, columns etc) for that you need dynamic sql. Commented Aug 17, 2022 at 10:54
  • Does this answer your question? Dynamic SQL Queries with Python and mySQL Commented Aug 17, 2022 at 16:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.