реализация Python db-api для sqlite имеет удобный метод executescript () для выполнения сценариев SQL с несколькими операторами. Это очень полезно, например, для создания базы данных. См. документация по драйверу sqlite.
Не могу найти аналогичный для драйвера Psycopg db-api для PostgreSQL. Существует ли executescript () в Psycopg? Любая альтернатива?
Спасибо
@CharlesDuffy Хорошо, отлично! Это означает, что я могу выполнить cursor.execute ("оператор sql1; оператор sql2; и т. д.")
Верный. Добавляем ответ по этому поводу.






Цитата из документация по проводному протоколу, выделено мной:
A simple query cycle is initiated by the frontend sending a Query message to the backend. The message includes an SQL command (or commands) expressed as a text string. The backend then sends one or more response messages depending on the contents of the query command string, and finally a ReadyForQuery response message. ReadyForQuery informs the frontend that it can safely send a new command. (It is not actually necessary for the frontend to wait for ReadyForQuery before issuing another command, but the frontend must then take responsibility for figuring out what happens if the earlier command fails and already-issued later commands succeed.)
...и позже:
Since a query string could contain several queries (separated by semicolons), there might be several such response sequences before the backend finishes processing the query string. ReadyForQuery is issued when the entire string has been processed and the backend is ready to accept a new query string.
Таким образом, стандартному вызову cursor.execute() можно дать список отдельных запросов, разделенных точкой с запятой, для выполнения.
Пожалуйста, добавьте сюда
executescript(sql_script)вместо ссылки на внешнюю ссылку