Custom SQL Queries
Execute custom analytical queries against historical SQLite and DuckDB datasets.
The zr history query command allows data engineers and QA leads to run arbitrary SQL queries directly against historical test execution data using DuckDB.
Usage
npx zr history query "<SQL_QUERY>"Interactive Output
By default, query results are formatted into an aligned ASCII terminal table:
npx zr history query "SELECT project_name, COUNT(*) as total_runs, AVG(duration_ms)/1000 as avg_sec FROM runs GROUP BY project_name"+---------------------+------------+---------+| project_name | total_runs | avg_sec |+---------------------+------------+---------+| Web App E2E | 142 | 18.4 || API Integration | 89 | 4.2 |+---------------------+------------+---------+Exporting Query Results to CSV
Append --export [filename] to write query results directly to a CSV spreadsheet:
npx zr history query "SELECT test_id, title, file_path, retry_count FROM tests WHERE status = 'flaky'" --export flaky-audit.csvCommon Analytical SQL Recipes
1. Top 10 Most Frequent Failure Signatures
SELECT error_message, COUNT(*) as occurrencesFROM test_resultsWHERE status = 'failed'GROUP BY error_messageORDER BY occurrences DESCLIMIT 10;2. Slowest Test Specs by P95 Duration
SELECT file_path, COUNT(*) as executions, ROUND(PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY duration_ms) / 1000, 2) as p95_secondsFROM test_resultsGROUP BY file_pathORDER BY p95_seconds DESCLIMIT 15;