{"action":"created","issue":{"url":"https://api.github.com/repos/jackc/pgx/issues/110","labels_url":"https://api.github.com/repos/jackc/pgx/issues/110/labels{/name}","comments_url":"https://api.github.com/repos/jackc/pgx/issues/110/comments","events_url":"https://api.github.com/repos/jackc/pgx/issues/110/events","html_url":"https://github.com/jackc/pgx/issues/110","id":120335619,"number":110,"title":"Means for dealing with session level state problems.","user":{"login":"josephglanville","id":605591,"avatar_url":"https://avatars.githubusercontent.com/u/605591?v=3","gravatar_id":"","url":"https://api.github.com/users/josephglanville","html_url":"https://github.com/josephglanville","followers_url":"https://api.github.com/users/josephglanville/followers","following_url":"https://api.github.com/users/josephglanville/following{/other_user}","gists_url":"https://api.github.com/users/josephglanville/gists{/gist_id}","starred_url":"https://api.github.com/users/josephglanville/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josephglanville/subscriptions","organizations_url":"https://api.github.com/users/josephglanville/orgs","repos_url":"https://api.github.com/users/josephglanville/repos","events_url":"https://api.github.com/users/josephglanville/events{/privacy}","received_events_url":"https://api.github.com/users/josephglanville/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-12-04T05:22:13Z","updated_at":"2015-12-07T14:39:33Z","closed_at":null,"body":"Hi @jackc,\r\n\r\nI encountered a problem with prepared queries and migrations that led me to think about how to deal with this class of problems with pgx.\r\nSpecifically my problem is we pre-prepare all queries on all connections using the `ConnPool` `AfterConnect` hook.\r\nIf then another instance of my program runs a database migration that alters the type of a column these prepared queries will become invalid if they make use of this column and return:\r\n```\r\nERROR: cached plan must not change result type (SQLSTATE 0A000)\r\n```\r\n\r\nThe issue here is that this is a session state error. To correct this I would need to either deallocate that query and re-prepare it or close that connection and allow the connection pool to establish a new one.\r\npgx currently doesn't provide any good interfaces for accomplishing this for queries that occur within a transaction. I have wrapped the `ConnPool` and can handle it on standard `Exec`/`Query` but the Tx object takes full control over the connection and wants to call `Release` on it itself.\r\n\r\nDo you have any ideas on how we could incorporate a hook or something that would be called on `Exec`/`Query` on a `Tx` that would then store a flag to call `Close` on the connection before `Release`? (because `Rollback` will probably be called after returning the `Error` anyways)"},"comment":{"url":"https://api.github.com/repos/jackc/pgx/issues/comments/162543347","html_url":"https://github.com/jackc/pgx/issues/110#issuecomment-162543347","issue_url":"https://api.github.com/repos/jackc/pgx/issues/110","id":162543347,"user":{"login":"josephglanville","id":605591,"avatar_url":"https://avatars.githubusercontent.com/u/605591?v=3","gravatar_id":"","url":"https://api.github.com/users/josephglanville","html_url":"https://github.com/josephglanville","followers_url":"https://api.github.com/users/josephglanville/followers","following_url":"https://api.github.com/users/josephglanville/following{/other_user}","gists_url":"https://api.github.com/users/josephglanville/gists{/gist_id}","starred_url":"https://api.github.com/users/josephglanville/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josephglanville/subscriptions","organizations_url":"https://api.github.com/users/josephglanville/orgs","repos_url":"https://api.github.com/users/josephglanville/repos","events_url":"https://api.github.com/users/josephglanville/events{/privacy}","received_events_url":"https://api.github.com/users/josephglanville/received_events","type":"User","site_admin":false},"created_at":"2015-12-07T14:39:33Z","updated_at":"2015-12-07T14:39:33Z","body":"4. Is definitely something I considered but I still hit the wall of how do I handle this a the connection pool level without handling at every point where I call Exec/Query or unpack a Row that contains an error?\r\n\r\nAs for when you change a column type that doesn't make a query invalid.. in my specific case it was a matter of changing from an enum to a varchar column with foreign key to a table with values populated with the previous contents of the enum. This scans to and from a string type still but is a different postgresql type."}}