moj-analytical-services / pydbtools

Python version of dbtools
https://moj-analytical-services.github.io/pydbtools/
10 stars 2 forks source link

Gk create temp table #27

Closed gkelly900 closed 3 years ago

gkelly900 commented 3 years ago

A bit messy. We can't use the sqlparse package as __temp__ could be used in quite a few locations (e.g. from, joins, where). I've used it to validate and clean queries though.

Have made it so check_sql fails if you pass more than one sql query separated by a ;. I've added some cleaning in that removes new lines from queries as this was messing some stuff up.

Have made it so replacing temp with dbname doesnt make everything lower case. The continued cleaning of strings is to stop newlines or trailing spaces causing errors.

Also added a bunch of tests.

Need to add docstring to check_sql function