When we raise a ActiveRecord::PreparedStatementCacheExpired we don't know which query raise the exception. It can be tricky to find it when you don't have database logs. I would like to add a message to ActiveRecord::PreparedStatementCacheExpired with the STATEMENT.
In Postgresql:
DROP TABLE IF EXISTS abc CASCADE;
DEALLOCATE FOO;
CREATE TABLE abc(i INT);
PREPARE FOO AS SELECT * FROM abc;
ALTER TABLE abc ADD COLUMN u INT;
EXECUTE FOO;Last query will generate in db logs:
2021-04-28 14:19:20.690 CEST [13223] ERROR: cached plan must not change result type
2021-04-28 14:19:20.690 CEST [13223] STATEMENT: EXECUTE FOO;
I would like PreparedStatementCacheExpired to generate ActiveRecord::PreparedStatementCacheExpired EXECUTE FOO or if I can SELECT * FROM abc;
May be interesting https://www.programmersought.com/article/72471262236/