1

I have a string set up the following way:

sql_string = ( """ select * from schema.table where column1 like '%object%' and column2 = '%s' """)%(x)

Unfortunately when I run my script, I get the following error:

TypeError: not enough arguments for format string

Is there any way for me to have a variable in my query string? I suspect that the percent signs in the column1 section of the query are what is causing issues.

Thanks!

2 Answers 2

2

You can escape the % using an other %:

sql_string = ( """ select * from schema.table where column1 like '%%object%%' and column2 = '%s' """)%(x)
Sign up to request clarification or add additional context in comments.

Comments

1

Use format function:

sql_string = ( """ select * from schema.table where column1 like '%object%' and column2 = '{}' """).format(x)

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.