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
ParameterTypeRequiredDescription
expressionVARCHARYesExpression over CONST values, such as K or CAST(N AS VARCHAR)
typeTYPEYesType of the result, required because the value is computed before type inference

Notes

  • Use it in persisted features that depend on CONST values: the formula is stored, not its value
  • Each query that reads the feature evaluates the formula against its own CONST block
  • 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 VARCHARstatus VARCHARmessage VARCHAR
FM.TUTORIALS.META.CST_EXTERNALCREATEDFeature 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