0

I'm working with Cloud Function. I have the following query working correctly:

# this is working
q = """ SELECT col1, col2
        FROM `my_table` 
        WHERE col1 = {} AND col2 = '{}'""".format(var1, var2)

however when trying to add a comment I have a Keyerror:

# this is not working
q = """ /* "{'query': 'some_name' */ 
        SELECT col1, col2
        FROM `my_table` 
        WHERE col1 = {} AND col2 = '{}'""".format(var1, var2)

The query is working with the comment if I'm removing the variables:

# this is working
q = """ /* "{'query': 'some_name' */ 
        SELECT col1, col2
        FROM `my_table` """

I'm using the following function to run my query:

def run_query(q):
    client = bigquery.Client()
    df_result = client.query(q).to_dataframe()
    return df_result

Why do I get this error? How should I comment in this context?

2
  • 1
    It seems you need to escape a curly brace in your comment by adding one more curly brace like this : /* "{{'query': 'some_name' */ Commented May 13, 2022 at 15:50
  • yes working and I understand why! thanks a lot. Commented May 13, 2022 at 19:41

1 Answer 1

1

As stated in the comments by @Jaytiger:

you need to escape a curly brace in your comment by adding one more curly brace like this :

/* "{{'query': 'some_name' */
Sign up to request clarification or add additional context in comments.

Comments

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.