Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python snowflake connection error because of spaces in query

I am trying to run a sql query in my python notebook,

code in cell looks like

sql = "select date, count(distinct id)
from table
group by 1;"

When I run I get an error of

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SyntaxError: unterminated string literal (detected at line 1)

I think I found the error, when I delete the space between the lines it goes away and runs such as:

"select date, count(distinct id) from table group by 1;"

The problem is thats my sample query, but I have large queries where it gets difficult to backspace them into one line, is there a way where I can get this to run without having on one line? Thanks

>Solution :

You can triple quotes and not double: “”” string””” or ”’ string”’
This will allow you to have your query on seperate lines rather that one line. For example, if you have a large query, you can have it go on multiple lines

sql = """SELECT *
         FROM TABLE
         WHERE 1=1
         AND stuff = stuff"""
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading