Reputation: 33
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?
Upvotes: 1
Views: 32
Reputation: 284
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}"')
Upvotes: 1