To get consistent behavior between queries, even when a query fails part way through, is to ensure the database connection has a clean / reset session state before issuing another command on the same connection.
- SQL Server has both a reset connection proc and protocol level bit that can be set to reset the connection.
- PostgreSQL has a "RESET ALL" command that will reset all set parameters.
- MySQL has a mysql_reset_connection() function that can be called to reset the session state.
- I think Oracle has a similar function as well.
It seems like there may be a missing life cycle step in the current "database/sql" driver model. If a Connection implements a driver.Reset interface, then before a connection is returned to the connection pool but after it is finished by the user, it is asynchronously called where a driver may choose to call one of the session reset methods above.
This was triggered by issue
https://github.com/denisenkom/go-mssqldb/issues/286 for the MS SQL Server driver. In my own SQL Server driver I implemented previously I reset the connection and set various SET parameters between connection uses. As a consume of SQL Drivers I find this to be important.
Please let me know if this sounds like something useful to you as well, or if you have concerns with the above.
Thanks, -Daniel