How can I specify for SQL to read a string in ordinary quote in DuckDB?

183 Views Asked by At

I have written a python queries with DuckDB:

import duckdb
con = duckdb.connect()
con.query('CREATE TABLE people(id INTEGER, name VARCHAR);')
con.query('INSERT INTO people VALUES (1, 'Mark'), (2, 'Hannes')')

But receive an error message:

con.query('INSERT INTO people VALUES (1, 'Mark'), (2, 'Hannes')') ^ SyntaxError: invalid syntax. Perhaps you forgot a comma?

As I understand the problem is with ordinary quote, which DB don`t see. How can I solve this problem?

I`m expecting to make insert query.

1

There are 1 best solutions below

1
On BEST ANSWER

Python has two different quotes you can use for strings - single (') and double (")

So you can write code like this:

con.query("INSERT INTO people VALUES (1, 'Mark'), (2, 'Hannes')")

or escape the internal quotes, like this:

con.query('INSERT INTO people VALUES (1, \'Mark\'), (2, \'Hannes\')')