{"action":"created","issue":{"url":"https://api.github.com/repos/lib/pq/issues/81","repository_url":"https://api.github.com/repos/lib/pq","labels_url":"https://api.github.com/repos/lib/pq/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/lib/pq/issues/81/comments","events_url":"https://api.github.com/repos/lib/pq/issues/81/events","html_url":"https://github.com/lib/pq/issues/81","id":11349974,"node_id":"MDU6SXNzdWUxMTM0OTk3NA==","number":81,"title":"Can't run two queries in a transaction?","user":{"login":"sbowman","id":47979,"node_id":"MDQ6VXNlcjQ3OTc5","avatar_url":"https://avatars1.githubusercontent.com/u/47979?v=4","gravatar_id":"","url":"https://api.github.com/users/sbowman","html_url":"https://github.com/sbowman","followers_url":"https://api.github.com/users/sbowman/followers","following_url":"https://api.github.com/users/sbowman/following{/other_user}","gists_url":"https://api.github.com/users/sbowman/gists{/gist_id}","starred_url":"https://api.github.com/users/sbowman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbowman/subscriptions","organizations_url":"https://api.github.com/users/sbowman/orgs","repos_url":"https://api.github.com/users/sbowman/repos","events_url":"https://api.github.com/users/sbowman/events{/privacy}","received_events_url":"https://api.github.com/users/sbowman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":38,"created_at":"2013-02-25T08:11:25Z","updated_at":"2018-09-21T18:47:28Z","closed_at":null,"author_association":"NONE","body":"I have some data I've loaded into a table from a CSV file that I want to massage into a master table.  When I try to do this in a transaction, pq just hangs on the second query I perform for no reason I can ascertain.\n\nHere's my code.  I chopped out everything after the second query; that query checks to see if the data is already migrated, and if not, runs all the create code and such.  If you comment out the \"select \\* from community_gnis\" line, the loop runs to completion, printing every city in the table.  If I leave the query in, it just hangs after the first city name.\n\n```\nif db, err := sql.Open(\"postgres\", \"user=postgres dbname=geo sslmode=disable\"); err == nil {\n    defer db.Close()\n    if tx, err := db.Begin(); err == nil {\n        if cities, err := tx.Query(\"select name, state, id, lon, lat from noaa.cities where id is not null\"); err == nil {\n\n            var name, state, gnis string\n            var longitude, latitude float32\n\n            for cities.Next() {\n\n                if err = cities.Scan(&name, &state, &gnis, &longitude, &latitude); err == nil {\n\n                    fmt.Println(\"Got city\", name, \"(\", gnis, \")\")\n\n                    tx.Query(\"select * from community_gnis where gnis = $1\", gnis)\n                }\n            }\n        }\n    }\n}\n```\n\nI'm new to Go, so maybe I'm doing things incorrectly here.  However, if I move the \"select \\* from community_gnis\" up above the \"select name, state...\" statement, the community_gnis statement runs fine and the \"select name, state...\" query will then be the one that hangs. \n\nIf I remove the transaction code and run everything against \"db\", e.g. \"db.Query\" instead of \"tx.Query\", etc., everything runs completely fine (though it doesn't run in a transaction, which is what I want).\n\nI've tried various combinations, using prepared statements, adding Close calls everywhere, etc.  Nothing works.  I'm 99% sure it's not the database, because I'm migrating this code from a Node JS app to test whether we should use Go or Node for our project, and the Node version runs completely in a transaction.  \n"},"comment":{"url":"https://api.github.com/repos/lib/pq/issues/comments/423635905","html_url":"https://github.com/lib/pq/issues/81#issuecomment-423635905","issue_url":"https://api.github.com/repos/lib/pq/issues/81","id":423635905,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzYzNTkwNQ==","user":{"login":"rbastic","id":373974,"node_id":"MDQ6VXNlcjM3Mzk3NA==","avatar_url":"https://avatars1.githubusercontent.com/u/373974?v=4","gravatar_id":"","url":"https://api.github.com/users/rbastic","html_url":"https://github.com/rbastic","followers_url":"https://api.github.com/users/rbastic/followers","following_url":"https://api.github.com/users/rbastic/following{/other_user}","gists_url":"https://api.github.com/users/rbastic/gists{/gist_id}","starred_url":"https://api.github.com/users/rbastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbastic/subscriptions","organizations_url":"https://api.github.com/users/rbastic/orgs","repos_url":"https://api.github.com/users/rbastic/repos","events_url":"https://api.github.com/users/rbastic/events{/privacy}","received_events_url":"https://api.github.com/users/rbastic/received_events","type":"User","site_admin":false},"created_at":"2018-09-21T18:47:28Z","updated_at":"2018-09-21T18:47:28Z","author_association":"NONE","body":"Has this moved at all in the favor of @timbunce 's solution?"}}
{"actor":{"display_login":"rbastic"}}