Fwd: How to sql scripts in a file?

Поиск
Список
Период
Сортировка
От Sándor Daku
Тема Fwd: How to sql scripts in a file?
Дата
Msg-id CAKyoTgZgf7dXEwd66HvpYAsizEo-unEMVgLTYRq2yGA27GSOHw@mail.gmail.com
обсуждение исходный текст
Ответ на How to sql scripts in a file?  (John Zhang <johnzhang06@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: John Zhang
Дата:
Сообщение: How to sql scripts in a file?
Следующее
От: Giuseppe Broccolo
Дата:
Сообщение: Re: [postgis-users] How to sql scripts in a file?