psql, BI tools, notebooks, database drivers — can connect to Lightdash and query your metrics and dimensions with SQL.
Your explores are exposed as tables, and their dimensions and metrics as columns. When you run a query, Lightdash compiles it through the semantic layer, so metric calculations, joins, and access controls are handled for you — you get the same numbers as in the Lightdash UI.
The Metrics SQL API is currently in beta and only available on Lightdash Enterprise plans. It’s disabled by default and must be enabled for your organization by an admin.For more information on our plans, visit our pricing page.
Connect
You can find copy-paste connection details in your project settings under Semantic Layer API. Connect with any Postgres-compatible client using:| Field | Value |
|---|---|
| Host | pg.<your_instance_name>.lightdash.cloud |
| Port | 5432 |
| Database | Your project UUID. The slugified project name also works, but changes if the project is renamed — the UUID is stable. You can find it in the Lightdash URL when viewing a project (/projects/<projectUuid>/...) |
| User | Your Lightdash account email. This value is informational — authentication is via the token |
| Password | A service account token (ldsvc_..., recommended) or a personal access token (ldpat_...) |
How queries work
- Tables are explores. Each explore in your project appears as a table, and
FROMtakes a single explore. Fields from tables joined in the explore are included as columns — joins are defined in the semantic layer, not in your SQL. - Columns are field IDs. Dimensions and metrics use their Lightdash field IDs, e.g.
orders_status,orders_total_order_amount. - Metrics are pre-aggregated. Select a metric like any other column and Lightdash computes the aggregation for you.
GROUP BYis optional — results are implicitly grouped by the dimensions you select. If you do write one, it’s validated against yourSELECTlist. - Results are limited to 500 rows by default. Add a
LIMITto override it.
WHERE (=, !=, <, <=, >, >=, IN, LIKE/ILIKE, BETWEEN, IS NULL, AND/OR), HAVING, ORDER BY, LIMIT, and calculated expressions in the SELECT list (arithmetic, functions, CASE, and window functions).
Examples
Discover explores and fields
The catalog is exposed throughinformation_schema. The field_type column on information_schema.columns tells you whether a field is a dimension or a metric:
Query a metric by a dimension
Select the dimensions and metrics you want — noGROUP BY or aggregate functions needed:
Filter and limit
Calculated expressions
Combine metrics and dimensions with expressions in theSELECT list, like table calculations in the Lightdash UI:
Query from Python
Because the interface speaks the Postgres wire protocol, existing Postgres drivers work:Self-hosting
If you self-host Lightdash, the Metrics SQL API server is disabled until you set thePGWIRE_PORT environment variable:
LIGHTDASH_LICENSE_KEY — see Enterprise License Keys.
Limitations
- No explicit joins, subqueries, or CTEs. Queries select from a single explore; joins are defined in the semantic layer.
- No DML. The API is read-only —
SELECTqueries only. - No custom metrics or period-over-period comparisons.
- Simple query protocol only. Prepared statements and bind parameters (the extended query protocol) aren’t supported.
psqland drivers sending plain-text queries work; some GUI tools won’t. - No
pg_catalogemulation. Schema browsers in GUI clients (e.g. DBeaver) won’t populate their sidebar — queryinformation_schema.tablesandinformation_schema.columnsinstead.