Skip to content

Add db_query_compare tool for SQL result set comparison#2

Open
frankhereford wants to merge 3 commits intofrank/db-profiling-toolingfrom
query-comparator
Open

Add db_query_compare tool for SQL result set comparison#2
frankhereford wants to merge 3 commits intofrank/db-profiling-toolingfrom
query-comparator

Conversation

@frankhereford
Copy link
Copy Markdown
Member

@frankhereford frankhereford commented May 6, 2026

Intent

In the course of working on the Moped PR 1840, I needed a tool which would compare and report on the differences in SQL result sets, at a field by field level. This is that tool. It is almost entirely written via 🤖 and to me, it has been a good example of how one-off tools are more at our fingertips than they have ever been.

Testing

  • Fire up your database of choice and load two queries into the query files.
  • Create a virtual environment for your python script and install the sole requirement so you can connect to your database
  • run the program, giving it credentials as arguments. It has a -h flag for help and my most recent invocation looks like this, aimed my local moped DB:
python ./compare_queries.py --user moped --password moped --dbname moped --host localhost --port 5432

- Introduced a new Python script `compare_queries.py` for comparing result sets from two SQL files against a database.
- Added example SQL query files `query_one.txt` and `query_two.txt` for testing.
- Included a `.gitignore` file to exclude `__pycache__` directories.
- Updated `requirements.txt` to include `psycopg` for database connectivity.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new toolbox/db_query_compare utility to execute two SQL files against the same PostgreSQL database and report row/field-level differences, intended to support validating query rewrites (e.g., comparing old vs. new SQL outputs).

Changes:

  • Introduces compare_queries.py CLI script to run both queries and print detailed mismatch diagnostics with exit codes suitable for scripting.
  • Adds psycopg[binary] dependency and a minimal .gitignore for Python bytecode.
  • Adds two bundled SQL files (query_one.txt, query_two.txt) as default inputs for the tool.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
toolbox/db_query_compare/compare_queries.py New Python CLI that runs both SQL files and compares result schemas/rows with detailed diff reporting.
toolbox/db_query_compare/requirements.txt Adds psycopg dependency needed to connect to PostgreSQL.
toolbox/db_query_compare/query_one.txt Bundled default “query one” SQL input for the comparison tool.
toolbox/db_query_compare/query_two.txt Bundled default “query two” SQL input for the comparison tool.
toolbox/db_query_compare/.gitignore Ignores __pycache__/ under the new tool directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread toolbox/db_query_compare/query_one.txt Outdated
Comment thread toolbox/db_query_compare/query_two.txt Outdated
Comment thread toolbox/db_query_compare/compare_queries.py
Comment thread toolbox/db_query_compare/compare_queries.py
Comment thread toolbox/db_query_compare/.gitignore
frankhereford and others added 2 commits May 6, 2026 14:49
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants