{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/1892","labels_url":"https://api.github.com/repos/rails/rails/issues/1892/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/1892/comments","events_url":"https://api.github.com/repos/rails/rails/issues/1892/events","html_url":"https://github.com/rails/rails/issues/1892","id":1134274,"number":1892,"title":"Cached query plans become invalid after migration changes column datatype","user":{"login":"jaredbeck","id":380809,"avatar_url":"https://avatars.githubusercontent.com/u/380809?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredbeck","html_url":"https://github.com/jaredbeck","followers_url":"https://api.github.com/users/jaredbeck/followers","following_url":"https://api.github.com/users/jaredbeck/following{/other_user}","gists_url":"https://api.github.com/users/jaredbeck/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredbeck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredbeck/subscriptions","organizations_url":"https://api.github.com/users/jaredbeck/orgs","repos_url":"https://api.github.com/users/jaredbeck/repos","events_url":"https://api.github.com/users/jaredbeck/events{/privacy}","received_events_url":"https://api.github.com/users/jaredbeck/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2011-06-29T01:18:44Z","updated_at":"2015-01-20T23:13:23Z","closed_at":"2011-10-19T01:00:15Z","body":"```ruby\r\n# Cause a query plan to be created\r\nThing.find(1)\r\n\r\n# Change column datatype (in this case, reduce the max. varchar length)\r\nchange_column :things, :name, :string, :limit => 10 \r\n\r\n# Try to reuse the same query plan\r\nThing.find(1) \r\n\r\n# => ActiveRecord::StatementInvalid: PGError: ERROR: cached plan must not change result type\r\n```\r\n\r\nThe workaround is easy.  One can simply restart one's application after such a migration.  Remembering to do so is the hard part :)\r\n\r\nWould it be possible for such a migration to automatically clear cached query plans?\r\n\r\nAre cached query plans a new feature in Rails?  Sorry, I can't say for sure which versions of rails this issue affects."},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/70754299","html_url":"https://github.com/rails/rails/issues/1892#issuecomment-70754299","issue_url":"https://api.github.com/repos/rails/rails/issues/1892","id":70754299,"user":{"login":"mockdeep","id":80543,"avatar_url":"https://avatars.githubusercontent.com/u/80543?v=3","gravatar_id":"","url":"https://api.github.com/users/mockdeep","html_url":"https://github.com/mockdeep","followers_url":"https://api.github.com/users/mockdeep/followers","following_url":"https://api.github.com/users/mockdeep/following{/other_user}","gists_url":"https://api.github.com/users/mockdeep/gists{/gist_id}","starred_url":"https://api.github.com/users/mockdeep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mockdeep/subscriptions","organizations_url":"https://api.github.com/users/mockdeep/orgs","repos_url":"https://api.github.com/users/mockdeep/repos","events_url":"https://api.github.com/users/mockdeep/events{/privacy}","received_events_url":"https://api.github.com/users/mockdeep/received_events","type":"User","site_admin":false},"created_at":"2015-01-20T23:13:23Z","updated_at":"2015-01-20T23:13:23Z","body":"We just saw this issue when deploying a migration to production. We added a column to the table, and a request that was in progress threw:\r\n\r\n```\r\nActiveRecord::StatementInvalid: PG::FeatureNotSupported: ERROR: cached plan must not change result type : SELECT \"forms\".* FROM \"forms\" WHERE \"forms\".\"id\" = $1 LIMIT 1\r\n```"}}