fix: Support PostgreSQL 12 in get_top_queries #132
Merged
+62
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #111 -
get_top_queriesnow works on PostgreSQL 12 and older.Problem
The
get_top_resource_queries()function hardcoded column names that were introduced in PostgreSQL 13:stddev_exec_time(wasstddev_timein PG12)wal_bytes(doesn't exist in PG12)This caused queries to fail on PG ≤ 12 with column not found errors.
Solution
Added version-aware column selection:
PostgreSQL 12 and older:
total_time,mean_time,stddev_timewal_bytes→0 AS wal_bytes(column doesn't exist)PostgreSQL 13+:
total_exec_time,mean_exec_time,stddev_exec_timewal_bytes(actual column)Also added
NULLIF()to prevent division by zero errors.Testing
postgres:12to test matrix inconftest.pyFiles Changed
src/postgres_mcp/top_queries/top_queries_calc.py- Version-aware column selectiontests/conftest.py- Added postgres:12 to test matrixtests/unit/top_queries/test_top_queries_calc.py- Added 2 new tests🤖 Generated with Claude Code