# SQL Engine

## Dialect

Altertable uses the **DuckDB SQL dialect** for all queries. If you are familiar with PostgreSQL or SQLite, most core syntax will be familiar.

Example query when Product Analytics is enabled for the environment:

```sql
SELECT
  distinct_id,
  COUNT(*) AS sessions
FROM product_analytics.analytics.web_sessions
WHERE started_at >= date_trunc('week', now())
GROUP BY distinct_id
ORDER BY sessions DESC
LIMIT 10;
```

For complete syntax reference, see the [DuckDB SQL Documentation](https://duckdb.org/docs/sql/introduction).

## Data Types

Altertable supports the same data types as DuckDB, including:

| Category | Types                                                  |
| -------- | ------------------------------------------------------ |
| Numeric  | `INTEGER`, `BIGINT`, `DOUBLE`, `DECIMAL`, `HUGEINT`    |
| Text     | `VARCHAR`, `TEXT`                                      |
| Temporal | `DATE`, `TIMESTAMP`, `TIMESTAMPTZ`, `TIME`, `INTERVAL` |
| Binary   | `BLOB`, `BITSTRING`                                    |
| Boolean  | `BOOLEAN`                                              |
| Nested   | `ARRAY`, `LIST`, `MAP`, `STRUCT`, `UNION`              |
| Special  | `UUID`, `JSON`                                         |

For a complete list of supported data types and their specifications, see the [DuckDB Data Types Overview](https://duckdb.org/docs/stable/sql/data_types/overview).

## Federated Queries

Connect multiple data sources, from BigQuery to Postgres catalogs, in the same SQL namespace:

```sql
SELECT
  u.email,
  b.total_revenue
FROM pg_production.users u
JOIN bigquery.revenue b
  ON u.id = b.user_id;
```

The engine handles cross-catalog federation automatically, optimizing query execution across all data sources in your lakehouse.