Home > front end >  How to insert single quote SQL queries into Trino as varchar?
How to insert single quote SQL queries into Trino as varchar?

Time:11-12

I have SQL queries in some data that looks includes single quotes, e.g. SELECT * from TABLE where date = '2022-11-11' this is causing issues when inserting into a table because of single quotes.

I'm using Python to process the data coming in but replacing the ''' with '\'' doesn't seem to be working. I thought escaping the single quotes but would work but queries to INSERT still fail. What would be the best way to handle inserting single quote SQL queries into a VARCHAR column?

CodePudding user response:

Double single quotes are used to escape single quote in Presto/Trino:

select 'SELECT * from TABLE where date = ''2022-11-11''';

Output:

_col0
SELECT * from TABLE where date = '2022-11-11'

So you can format your query correspondingly

  • Related