EVAL_CONST()
All functions > METAPROGRAMMING > EVAL_CONST()
Returns the result of evaluating a constant formula as a literal.
Signatures
Returns: The constant value as a literal of the given type
EVAL_CONST( expression AS type ) → T sql
| Parameter | Type | Required | Description |
|---|---|---|---|
expression | VARCHAR | Yes | Expression over CONST values, such as K or CAST(N AS VARCHAR) |
type | TYPE | Yes | Type of the result, required because the value is computed before type inference |
Notes
- Use it in persisted features that depend on
CONSTvalues: the formula is stored, not its value - Each query that reads the feature evaluates the formula against its own
CONSTblock - The expression may only use constants: no feature that depends on inputs
- Restricted to offline use
See also
Examples
Persist a feature that reads a CONST value
FeatureQL
CREATE OR REPLACE FEATURES AS
CONST EXTERNAL_CONSTANT := 0
PERSIST
fm.tutorials.meta.cst_external := ADD(
EVAL_CONST(2*EXTERNAL_CONSTANT AS BIGINT),
1
)
;Result
| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.META.CST_EXTERNAL | CREATED | Feature created as not exists |
Each reader's CONST block supplies the value
FeatureQL
CONST EXTERNAL_CONSTANT := 5
RETURN
fm.tutorials.meta.cst_external
;Result
| FM.TUTORIALS.META.CST_EXTERNAL BIGINT |
|---|
| 11 |