Fwd: How to sql scripts in a file? - Mailing list pgsql-sql

From Sándor Daku
Subject Fwd: How to sql scripts in a file?
Date
Msg-id CAKyoTgZgf7dXEwd66HvpYAsizEo-unEMVgLTYRq2yGA27GSOHw@mail.gmail.com
Whole thread Raw
In response to How to sql scripts in a file?  (John Zhang <johnzhang06@gmail.com>)
List pgsql-sql
On Thu, 23 Apr 2020 at 14:43, John Zhang <johnzhang06@gmail.com> wrote:
Hello all,

I have a need to execute sql scripts in a file with comments in Python 2.7. 
here is m code snippet:

sqlF = r'{}\{}'.format(sFldr_sql,sSQLFile)
sql_file_contents = open(sqlF,'r').read()
cur.execute(sql_file_contents)
 
the file can be executed from pgAdmin successfully. However, the code above runs quietly without any issues raised but NO results was worked out.

Hi John,

Psycopg2 I guess. 
You have to commit the changes with calling commit() on the connection(not on the cursor!).

Or - 2.5 and above - you can use cursors and connections as context managers and it will be taken care of automatically.


Regards,
Sándor


pgsql-sql by date:

Previous
From: John Zhang
Date:
Subject: How to sql scripts in a file?
Next
From: Giuseppe Broccolo
Date:
Subject: Re: [postgis-users] How to sql scripts in a file?