Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save benoittgt/8df281e1ac4bbf69895e348d4174c1dc to your computer and use it in GitHub Desktop.

Select an option

Save benoittgt/8df281e1ac4bbf69895e348d4174c1dc to your computer and use it in GitHub Desktop.

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;

@benoittgt
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment