Concepts → Internal Query Expression
About an Internal Query Expression
An internal query expression queries a physical schema table or runtime business view. In this regard, the adjective “internal” references physical schemas and business schemas within a given tenant. The objective of an internal query expression is to return a single scalar value or an array of scalar values.
You use the Formula Builder to create the internal query expression. The internal query expression requires either the query()
or queryDistinct()
built-in function. Both functions require a fully qualified name for a single column in a physical schema table or a runtime business view. An internal query expression can also contain one or more predicates for filtering query results.
When you use a variable that returns a date or a date value, make sure that the value is in the following format yyyy-MM-dd
.
Internal query expression context
The context for an internal query expression is an internal session variable or an In Query
filter operator and formula expression. The internal query expression context determines the validation rules for the expression itself and the limitations of the expression.
For example, an internal query expression can reference in a predicate another internal query expression or another internal session variable.
Valid references in an internal query expression
Here are the valid references in an internal query expression:
- Referenceable columns
- Supported built-in functions
- Referenceable variables
View Access Rights
In order to reference a column or variable in an internal query expression, you must have View access rights to the grandparent object (schema or business schema) or the variable.
Referenceable columns
A referenceable column has a fully qualified name. A referenceable column exists in a physical schema or runtime business view. Here are the possible types of referenceable columns in an internal query expression:
- Physical_Schema.Table.Column
- Physical_Schema.Table.Formula_Column
- Physical_Schema.Incorta_Table.Column
- Physical_Schema.Incorta_Table.Formula_Column
- Physical_Schema.Incorta_Analyzer_Table.Column
- Physical_Schema.Incorta_Analyzer_Table.Formula_Column
- Physical_Schema.Incorta_SQL_Table.Column
- Business_Schema.View.Column
- Business_Schema.View.Formula_Column
- Business_Schema.Incorta_View.Column
- Business_Schema.Incorta_View.Formula_Column
Supported built-in functions
The following are the types of valid built-in functions for an internal query expression:
Function Type | Description | Example |
---|---|---|
Boolean | Functions that evaluate to True or False | and, between, contains, endsWith, in, inList, isNan, isNull, like, not, or, startsWith |
Conditional Statement | Statements that return a value based on the evaluation of a parameter | case, decode, and if |
Conversion | Functions that convert the Incorta Data Type of a parameter. In addition, functions that manipulate Timestamp and Date values for different return values. | day, double, monthName, parseDouble, string, toChar, and year |
Miscellaneous | Functions with assorted uses | descendantOf, lookup, rowNumber, and schemaRefreshTime |
Arithmetic | Functions that take one or more values and return a single value. | abs, ceil, exp, floor, max, min, mod, rnd, round, sqrt, and trunc |
Date | Functions that manipulate Timestamp and Date values. | addDays, date, month, removeTime, weekday, and year |
String | Functions that return string values or return values based on string parameters. | bin, concat, find, ifNull, repeat, rTrim, and upper |
Query | Functions that act as the base query function or query filtering functions. | query and queryDistinct |
Internal query expressions are incompatible with built-in aggregation or analytics functions. They will not be listed in the Formula Builder when building an expression.
Referenceable variables and functions
The following are the types of variables and functions that are referenceable in an internal query expression:
Variable Type | Internal Session Variable | InQuery |
---|---|---|
Built-in function | ✔ | ✔ |
Date system variable | ✔ | ✔ |
External session variable | ✔ | ✔ |
Filter expression session variable | ||
Internal session variable | ✔ | ✔ |
Global session variable | ✔ | ✔ |
Miscellaneous system variable | ✔ | ✔ |
Presentation variable | ✔ |
Internal query expression examples
The following are several examples of internal query expressions:
Example with fully qualified column name:
query(SALES.COUNTRIES.COUNTRY_NAME)
Example with referenceable internal or external session variable:
queryDistinct(sch_IncortaMetadata.GROUP.ID,sch_IncortaMetadata.GROUP.NAME = "grp_Admin",sch_IncortaMetadata.GROUP.TENANTID = $ivar_getTenantID)
Both Internal and external session variables are referenced in an internal query expression using the same syntax, using a $
before the variable name.
Example with a referenceable system variable:
queryDistinct(SALES.SALES.PROD_ID,SALES.SALES.TIME_ID = $currentDate)
Examples with Boolean functions:
Example 1:
query(if(or(SALES.SALES.AMOUNT_SOLD > 3600,SALES.SALES.COST_OF_GOODS <= 2000),"Green","Red"),trim(upper(SALES.COUNTRIES.COUNTRY_NAME)) = trim(upper($country)),SALES.SALES.TIME_ID = date("2007-12-31"))
Example 2:
query(SALES.SALES.AMOUNT_SOLD,and(SALES.COUNTRIES.COUNTRY_NAME = "Italy",SALES.SALES.AMOUNT_SOLD > 6950))
Following is an example internal query expression using a conditional statement in the query:
queryDistinct(if(SALES.SALES.AMOUNT_SOLD >= int($evar_threshold),"True","False"))
Because the result of a session variable is always a string or an array of strings, you must cast the session variable result value when you compare it to a non-string value.