Skip to main content

Constant

Syntax

constant: constant_name {
value: "string value"
sql_value: SQL expression that returns one value ;;
}

Example

constant: TABLE_PREFIX {
value: "mage_"
}

view: orders {
sql_table_name: @{TABLE_PREFIX}orders ;;
}

constant: LANGUAGE_ID {
sql_value: SELECT lang_id FROM languages LIMIT 1 ;;
}

view: customer_groups {
derived_table: {
sql: @sql
SELECT cg.*, cgt.name FROM groups cg
LEFT JOIN translations cgt
ON cgt.customer_group_id = cg.id AND cgt.language_id = "@{LANGUAGE_ID}"
;;
}
}

constant: today {
sql_value: SELECT TO_CHAR((DATE_TRUNC('day', NOW()) + '0 days')::date, 'DD-MM-YYYY') ;;
}
constant: tomorrow {
sql_value: SELECT TO_CHAR((DATE_TRUNC('day', NOW()) + '1 days')::date, 'DD-MM-YYYY') ;;
}
constant: monday {
sql_value: SELECT TO_CHAR((DATE_TRUNC('week', NOW()) + '0 days')::date, 'DD-MM-YYYY') ;;
}
constant: friday {
sql_value: SELECT TO_CHAR((DATE_TRUNC('week', NOW()) + '4 days')::date, 'DD-MM-YYYY') ;;
}
#The constant can be used in other AML or as filter value @{tomorrow}