From 45bf5a51a9544ff9e2e2fe767bbf0b48f51a47e0 Mon Sep 17 00:00:00 2001 From: Jose Rego Date: 2025年8月26日 14:15:23 +0100 Subject: [PATCH 1/2] docs: parameters type --- guides/using-parameters.mdx | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/guides/using-parameters.mdx b/guides/using-parameters.mdx index b4fd4f2..f0877fc 100644 --- a/guides/using-parameters.mdx +++ b/guides/using-parameters.mdx @@ -44,6 +44,61 @@ Parameters can be referenced in many places throughout your Lightdash project: 7. **Additional Dimensions**: Use parameters in the SQL definition of an [additional dimension](/references/dimensions#additional-dimensions) 8. **Custom Dimensions**: Use parameters in [custom dimension](/references/custom-fields#custom-sql) definitions +## Parameter types + +Parameters in Lightdash support different data types to help you work with various kinds of data. By default, all parameters are treated as strings, but you can convert them to other types as needed. + +### Supported parameter types + +Lightdash officially supports the following parameter types: + +- **String** (default): Text values +- **Number**: Numeric values (integers and decimals) + +### Type conversion workarounds + +While not officially supported yet, you can work around for other data types via SQL type casting. +To convert a parameter to a specific type, use the `::` syntax followed by the type name: + +```sql +${lightdash.parameters.parameter_name::type} +``` + + + The type conversion happens at the SQL level, so the available types depend on your database system (PostgreSQL, BigQuery, Snowflake, etc.). Common types like `integer`, `numeric`, `date`, `timestamp`, and `boolean` are supported across most databases. + + +#### Date conversion + +As a workaround, you can use `::date` for dates or `::timestamp` for datetime values: + +```sql +-- Convert to date (workaround) +WHERE ${TABLE}.order_date>= ${lightdash.parameters.start_date::date} + +-- Convert to timestamp (workaround) +WHERE ${TABLE}.created_at>= ${lightdash.parameters.start_datetime::timestamp} +``` + +#### Boolean conversion + +As a workaround, you can use `::boolean` to convert string values like "true"/"false" to boolean: + +```sql +-- Convert to boolean (workaround) +WHERE ${TABLE}.is_active = ${lightdash.parameters.active_only::boolean} +``` + +#### Other type conversions + +You can use any SQL type conversion that your database supports: + +```sql +-- Convert to specific database types +WHERE ${TABLE}.category_id = ${lightdash.parameters.category::uuid} +WHERE ${TABLE}.amount = ${lightdash.parameters.amount::decimal(10,2)} +``` + ## How to reference parameters in SQL ### Project-level parameters From f6f42e46850775a41aba04c14808453ff8ffefcc Mon Sep 17 00:00:00 2001 From: Jose Rego Date: 2025年8月26日 14:35:40 +0100 Subject: [PATCH 2/2] docs: amend type examples --- guides/using-parameters.mdx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/guides/using-parameters.mdx b/guides/using-parameters.mdx index f0877fc..24e2fc2 100644 --- a/guides/using-parameters.mdx +++ b/guides/using-parameters.mdx @@ -61,7 +61,7 @@ While not officially supported yet, you can work around for other data types via To convert a parameter to a specific type, use the `::` syntax followed by the type name: ```sql -${lightdash.parameters.parameter_name::type} +${lightdash.parameters.parameter_name}::type ``` @@ -74,10 +74,10 @@ As a workaround, you can use `::date` for dates or `::timestamp` for datetime va ```sql -- Convert to date (workaround) -WHERE ${TABLE}.order_date>= ${lightdash.parameters.start_date::date} +WHERE ${TABLE}.order_date>= ${lightdash.parameters.start_date}::date -- Convert to timestamp (workaround) -WHERE ${TABLE}.created_at>= ${lightdash.parameters.start_datetime::timestamp} +WHERE ${TABLE}.created_at>= ${lightdash.parameters.start_datetime}::timestamp ``` #### Boolean conversion @@ -86,7 +86,7 @@ As a workaround, you can use `::boolean` to convert string values like "true"/"f ```sql -- Convert to boolean (workaround) -WHERE ${TABLE}.is_active = ${lightdash.parameters.active_only::boolean} +WHERE ${TABLE}.is_active = ${lightdash.parameters.active_only}::boolean ``` #### Other type conversions @@ -95,8 +95,8 @@ You can use any SQL type conversion that your database supports: ```sql -- Convert to specific database types -WHERE ${TABLE}.category_id = ${lightdash.parameters.category::uuid} -WHERE ${TABLE}.amount = ${lightdash.parameters.amount::decimal(10,2)} +WHERE ${TABLE}.category_id = ${lightdash.parameters.category}::uuid +WHERE ${TABLE}.amount = ${lightdash.parameters.amount}::decimal(10,2) ``` ## How to reference parameters in SQL

AltStyle によって変換されたページ (->オリジナル) /