On Tue, Oct 11, 2011 at 12:32 AM, Brian M <[email protected]> wrote:
> Try opening your file, reading its contents and then having db.executesql()
> execute what was read. Should work assuming the file's contents can be run
> by psycopg2 (i.e some special psql stuff might not work)
>
> #untested code
> f = open('/path/to/file.sql', 'r')
> db.executesql(f.read())
>
That works, but prefer to run inside a context:
with open("/path/to/file,sql", "r") as sql:
code = sql.read()
# here you can do some parsing, remove spaces, replace things
db.executesql(code)