0

I want to insert a variety of SQL queries into a Trino table as a VARCHAR.

There are a multitude of items that throw errors for example single quotes, keywords like "table" being a column name, -- SQL comments that throw errors when Trino is reading the SQL INSERT query.

Is there a data type where I can just dump string type data that may contain things like keywords, SQL comments, single quotes? Trying VARCHAR doesn't seem to be the answer.

Paul
  • 1,101
  • 1
  • 11
  • 20
  • I don't know Trino, but VARCHAR should be able to store the strings. This is just text and it doesn't matter whether this string contains special characters or SQL keywords or not. I suppose it is rather the method used to insert the data that is the problem. – Thorsten Kettner Nov 16 '22 at 21:31
  • Yeah, so I'm just taking the string type and directly inserting into a VARCHAR column. But when Trino goes to read it e.g. "SET .... -- something" or SELECT ... col = 'something'" those single quotes or comments will throw errors as Trino reads the INSERT query. – Paul Nov 16 '22 at 21:32
  • 1
    This is an insert statement with keywords and escaped single quotes. This should work in most DBMS: `insert into mytable (sql) values ('select * from some_table where some_column like ''%hello%''');` – Thorsten Kettner Nov 16 '22 at 21:36
  • Yeah, been trying that as well. Too many permutations to catch at the moment... might be better to try and catch a malformed query before firing. Any knowledge on libraries (Python) that would catch whether a Trino query is valid or not? – Paul Nov 16 '22 at 22:03
  • Does this answer your question? [How to insert single quote SQL queries into Trino as varchar?](https://stackoverflow.com/questions/74408495/how-to-insert-single-quote-sql-queries-into-trino-as-varchar) – Guru Stron Nov 17 '22 at 13:45

0 Answers0