Skip to content
Advertisement

Single Quote in Cursor Execute for Snowflake Connector

I am trying to update a table from the Snowflake Connector in python to a Snowflake table;

update TABLE set X = 100 where Y = 'Applebee's'

To escape the single quote in the Snowflake UI, I would format the “where” clause to be

where Y = 'Applebee's'

Also tried:

where Y = 'Applebee''s'

However, no fix that I have tried is succeeding to workaround this error in python. Is there a way to do this from python, in a one step process, without any steps in Snowflake? I only care about workarounds from python.

Advertisement

Answer

In all SQL, the only true way to avoid weird characters and not have to account for each possibility is to parametrized your sql calls either as some sort of stored procedure call or a parametrized call from your client – in this case python.

In general this means, never have a case where you are concatenating a sql string to the value of a where clause like you have above.

Here’s an example of how to parametrize a statement in python here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement