Skip to content

Postgres execute API

Use POST /v1/execute/postgres when you want SQL Tamer to run both the original query and the rewritten query against Postgres for you.

Use it for demos, validation, or benchmark-style checks. It is not the main production integration path.

Unlike the rewrite API, this endpoint opens the Postgres connection itself, so most teams use it only for short-lived validation.

Replace SQLTAMER_BASE_URL with your API base URL before running the examples on this page.

Request

curl -X POST "$SQLTAMER_BASE_URL/v1/execute/postgres" \
  -H "Authorization: Bearer $SQLTAMER_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{
    "sql": "SELECT COUNT(*) FROM users WHERE id IN (101, 202, 303, 404, 505)",
    "database_url": "postgresql://app:secret@db.internal/app",
    "preview_rows_limit": 20,
    "dialect": "postgres",
    "min_in_list_items": 3
  }'

Response excerpt

{
  "main_sql": [
    "SELECT COUNT(*) FROM users WHERE id = ANY($1::BIGINT[])"
  ],
  "main_bindings": [
    [
      {
        "kind": "postgres_bigint_array",
        "values": [101, 202, 303, 404, 505]
      }
    ]
  ],
  "execution": {
    "baseline_ms": 110.0,
    "rewritten_ms": 24.9,
    "rewrite_setup_ms": 0.0,
    "copy_ms": 0.0,
    "rewrite_main_ms": 24.9,
    "cleanup_ms": 0.0,
    "result_check": "preview_matched"
  }
}

When to use it

  • You want SQL Tamer to prove the rewrite against a live Postgres database.
  • You want timing plus a preview result set.
  • You are testing a rewrite idea before wiring it into application code.

When not to use it

  • As the default production integration path.
  • When your app already owns the database connection and can execute the rewrite plan directly.
  • When you do not want to send a Postgres connection string to SQL Tamer.

For the normal application flow, use the rewrite API plus the Postgres integration guide.