Can I pass strings with reserved characters?

Viewed 28

When I try this:

db = 'ACS-Sociodemographics(USA,CensusBlockGroups,2018)'
ctx.cursor().execute(f"USE DATABASE {db}")

I get this error:

ProgrammingError: 001003 (42000): SQL compilation error:
syntax error line 1 at position 16 unexpected '-'.

Is there a recommended way to pass a string with reserved characters?

1 Answers

Yes, the db name needs to be encased in double quotes. To make life easier, wrap the whole thing in single quotes like so:

ctx.cursor().execute(f'USE DATABASE "{db}"')
Related