I have a psycopg connection with autocommit turned on. Say, I run a query that is a combination of multiple queries, e.g.:
query = ";".join([create_table, insert_data, analyze_table])
conn.execute(query)
Is this batch executed in a single transaction or multiple transactions? What happens if a query in the middle fails?
From Chain multiple statements within Psycopg2
In SQL chaining refers to the process of linking multiple SQL statements together into a single string, separated by semicolons. This allows you to execute multiple SQL statements at once, without having to execute them individually.
For example, you might chain together a SELECT statement to retrieve data from a table, followed by an UPDATE statement to modify the data, and then a DELETE statement to remove it. When using chaining, it is important to note that each statement will be executed in the order they appear in the chain and that the results of one statement can be used in the next one. Additionally, when chaining SQL statements, if any statement in the chain fails, the entire chain will fail and none of the statements will be executed.