I've noticed a strange behavior in Go's database/sql package, using the PostgreSQL driver from lib/pq. Basically if I use a database connection for a query while I'm building a transaction on the same connection, I enter in a dead lock and the program blocks (I need to manually restart the database server to make it work again). In the example code below, I would get stuck at the select statement, and the second insert statement would never be executed (while if I remove the query the code executes normally).
tx, _ := connection.Begin()
tx.Exec(insert_statement)
rows, _ := connection.Query(select_statement)
rows.Close()
tx.Exec(insert_statement_2)
tx.Commit()
Is this normal? Should I create a new database connection every time I want to use transactions?