From: | Sándor Daku <daku(dot)sandor(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Fwd: How to sql scripts in a file? |
Date: | 2020-04-23 13:08:19 |
Message-ID: | CAKyoTgZgf7dXEwd66HvpYAsizEo-unEMVgLTYRq2yGA27GSOHw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Thu, 23 Apr 2020 at 14:43, John Zhang <johnzhang06(at)gmail(dot)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.
See details here:
https://www.psycopg.org/docs/usage.html#transactions-control
Regards,
Sándor
From | Date | Subject | |
---|---|---|---|
Next Message | Giuseppe Broccolo | 2020-04-23 13:37:24 | Re: [postgis-users] How to sql scripts in a file? |
Previous Message | John Zhang | 2020-04-23 12:42:46 | How to sql scripts in a file? |