diff --git a/guides/using-parameters.mdx b/guides/using-parameters.mdx index b4fd4f2..24e2fc2 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

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