Smart Query

Smart Query lets you describe what you want, then reviews a generated SQL statement you can edit and run. It’s designed for speed and safety—Postgres-only, single-statement execution, and strict schema enforcement for your company.

Write a Great Prompt

  • State the goal and the time window (e.g., “last 90 days”).
  • Mention relevant tables or fields if you know them.
  • Clarify the grain: by day, by month, by product, etc.
  • Keep table/column names lowercase to match imports.

Review & Edit SQL

The generated SQL appears in an editable box. Adjust filters, add columns, tweak grouping and ordering. The Console enforces a single SQL statement for safety.

Run & Export

  • Press Run to execute and see results below.
  • Export as JSON or CSV from the results box.
  • Copy to clipboard for use elsewhere.

Guardrails

  • PostgreSQL syntax only; no cross-company schema access.
  • Automatic patches for common date/time casting patterns.
  • Dangerous commands (DDL/DML) are blocked in the Console.
Tip: If migrating queries from MySQL, replace functions like DATE_FORMAT or YEAR() with Postgres equivalents (e.g., TO_CHAR, EXTRACT, DATE_TRUNC). Cast text date columns to ::date when grouping by month/day.

Troubleshooting

Syntax error or empty results

Confirm table/column names (lowercase) and date ranges. Validate joins and casts (e.g., text to ::date or ::timestamp).

“Only one statement allowed”

Remove extra semicolons, stray CTEs, or comments that create multiple statements. Keep it to one SELECT ....

Join or date casting issues

Ensure join keys match in type. For time grouping, try DATE_TRUNC('month', your_ts) and ensure your_ts is a timestamp or cast appropriately.

Next: build visuals in the Report Builder.