--- title: "Value from SQL query" slug: "core-native-sql-value" updated: 2026-04-27T08:20:49Z published: 2026-04-27T08:20:49Z canonical: "docs.lobstersoftware.com/core-native-sql-value" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.lobstersoftware.com/llms.txt > Use this file to discover all available pages before exploring further. # Value from SQL query *See also:* [Execute SQL query](/v1/docs/en/core-native-sql-actor-configuration) (Event action) > [!NOTE] > **Value resolver – Abstract** > > **Purpose:** Passes a single native SQL SELECT statement to a database that must be accessible to the **Lobster Data Platform/Orchestration** server via the specified **Alias**, and returns the result rows as a list of client objects. > > > [!TIP] > > Tooltip > > > > - **Usage**: As long as the **Lobster Data Platform/Orchestration** server has database access for the parameterized **Alias**, the **SQL Query** is executed – taking into account the configured *parameters* for inputting data from the call context, if applicable. Result rows appear as entries of a list, where each entry is a client object whose field names correspond to the projections (or "columns") of the query. > > - **Parameter**: > > - The **Alias** parameter addresses the database via an alias name configured for the **Lobster Data Platform/Orchestration** server. The name can be determined either by static direct entry in the configuration or via value resolvers at runtime > > - The **SQL Query** parameter defines an SQL SELECT statement in which *parameters* whose values are determined at runtime can be referred to instead of values (e.g. in criteria of the WHERE condition). > > - For each parameter used in the **SQL Query**, a "variable" must be configured with an integer index value as the **Variable name** value resolver that returns values in a matching data type at runtime. > > - **NOTE:** If a query returns no rows, the *result variable* contains an empty list that satisfies a check by [Is empty](/v1/docs/en/core-is-empty-matcher), but not a comparison like "[Equals](/v1/docs/en/core-equals-matcher) to no value". *![images/download/attachments/177909604/image-2024-9-2_15-26-30-version-1-modificationdate-1725283589996-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image-2024-9-2_15-26-30-version-1-modificationdate-1725283589996-api-v2.png)* The [Value from SQL query](/v1/docs/en/core-native-sql-value) value resolver passes a single native SQL SELECT statement to a database that must be accessible to the **Lobster Data Platform/Orchestration** server via the specified **Alias**, and returns the result rows as a list of client objects. Unlike the [Execute SQL query](/v1/docs/en/core-native-sql-actor-configuration) event action, the [Value from SQL query](/v1/docs/en/core-native-sql-value) value resolver can only execute SELECT statements. The value resolver returns their return values as a list of client objects. Each client object represents one *result row.* The "column names" of the query (projections) appear as fields of each client object in the list. Depending on the database system, the column names appear either uniformly in upper case, uniformly in lower case, or case-sensitive . In any case, the respective notation must match exactly ("case-sensitive") when accessing the data fields in **Lobster Data Platform/Orchestration** (e.g. via an [Object property](/v1/docs/en/core-property-resolver) value resolver). **NOTE:** If a query returns no rows, the *result variable* contains an empty list that satisfies an [Is empty](/v1/docs/en/core-is-empty-matcher) check, but not a comparison like ‘[Equals](/v1/docs/en/core-equals-matcher) no value’. The SQL statement can include the values of variables from the context of the current event handling via type-safe placeholders according to the **Lobster Data Platform/Integration** query syntax. ## Configuration The **Alias** parameter can be specified as static text or as the return value of a value resolver. It must point to a database that can be accessed by the **Lobster Data Platform/Orchestration** server. The **SQL Query** parameter defines the SQL statement to be executed in the native syntax of the database addressed by **Alias**, if necessary taking into account more typical *placeholders*, in the place of which the **Value** of one variable each from the event handling context is inserted at runtime. - For the definition of these placeholders the **Lobster Data Platform/Integration** query syntax with the structure `@<index>:<typ>@` is used, e.g. `@1:s@` for a string value or `@2:t@` for a timestamp. - The `<index>` must be a positive integer, which is also used as **Variable name** within the configuration. The values used do not have to be assigned without gaps and in ascending order. - As `<typ>` an identification letter for a data type must be specified ("`l`" long, "`s`" string, for a complete list see **Lobster Data Platform/Integration** query syntax), which must match the intended use for the placeholder. - For all placeholders used in the **SQL Query**, a corresponding **Variable name** must be explicitly configured with a value resolver whose return value must correspond to the data type of the *placeholder* or at least be suitably convertible. - The same **Variable name** can be referenced by several *placeholders*, which can even specify different data types if needed, as long as any value occurring at runtime can be converted to all target data types. **NOTE:** *Placeholders* can only be used at positions in the SQL statement that affect *values* and not, for example, to dynamically assign fields, table names or keywords to the syntax. However, the value for the **SQL Query** parameter as a whole can be built dynamically (e.g. via [Concat strings](/v1/docs/en/core-concat-string-resolver)) to achieve corresponding flexibility. ## Example The "Creator" (`creatorId`) field of an entity refers via a `Long` value to the account of the user (see [Users](/v1/docs/en/base-user)) or guest user (see [Guest users](/v1/docs/en/base-guest-user)) who created the entity – i.e. saved it for the first time. A positive `creatorId` refers to the ID of a user, while a negative value for the `creatorId` refers to a guest user as creator. However, the possibility that guest users create entities is excluded in the following example, so that only positive values for the `creatorId` can occur. Based on a `creatorId`, the user name of the relevant user is to be identified as the "creator" of the entity in a notification. This can be easily achieved via the lookup function for entities of the [Input object (type safe)](/v1/docs/en/core-root-entity-resolver) value resolver. However, accessing the user account via the `creatorId` by [Input object (type safe)](/v1/docs/en/core-root-entity-resolver) value resolver fails if the account in question has been deleted since the entity was created. A [Search](/v1/docs/en/core-search) would not return a match either, since a deleted user account actually no longer exists in the relevant table of the **Lobster Data Platform/Orchestration** database (*here*: `base_user`). However, since **Lobster Data Platform/Orchestration** keeps information on the change history for [Users](/v1/docs/en/base-user), the user name of a deleted user account can be looked up in the "change history". The [Value from SQL query](/v1/docs/en/core-native-sql-value) value resolver provides the necessary read access to the relevant database table, in this use case: `base_user_history`. Configuration: The following SELECT statement returns the last used username of a user account for an ID given in the integer parameter 1 (placeholder `@1:i`): PostGreSQL-example ```plaintext SELECT username FROM base_user_history WHERE id=@1:i@ ORDER BY entry_valid_from DESC LIMIT 1 ``` | The value resolver chain shown on the right identifies the "Creator" of the entity present as a *reference object* either by the "Username" (`userName`) field of an *existing* user account or – if the account has been deleted – by the last relevant entry in the change history: - The first [Object property](/v1/docs/en/core-property-resolver) value resolver returns the `Long` value from the `creatorId` field, which identifies the "Creator" account. - The concatenated [Input object (type safe)](/v1/docs/en/core-root-entity-resolver) value resolver is used here to look up the complete user account (**Type** "User"/`User`) starting from the ID. - The concatenated second [Object property](/v1/docs/en/core-property-resolver) value resolver returns the value of the "Username" (`username`) field if the user account exists. Otherwise the return value is `$null`. - The concatenated [Default value](/v1/docs/en/core-default-value-resolver) resolver evaluates the value resolvers defined in the **Default value** parameter exactly when the *input value* is `$null`. Otherwise, the *input value* is output unchanged. The **Default value** is defined as follows: - The [Value from SQL query](/v1/docs/en/core-native-sql-value) value resolver refers to the **Lobster Data Platform/Orchestration** database by **Alias** `scm`. - The **SQL Query** defines the above SELECT statement as static text with an `Integer` parameter (`@1:i@`). - Under **Variable name** `1` the value resolvers are defined, which "insert" the ID of the searched user account as a parameter into the statement at runtime. The automatically filled variable `entity` an be used to address the *reference object* in order to access its "Creator" (`creatorId`) field again. - Finally, the column `username` is read from the first "match" from the SQL query: - The **SQL Query** specifies by `LIMIT 1` that a maximum of one result row is returned from the query. However, this is formally the only element of a list (in the return value of the [Value from SQL query](/v1/docs/en/core-native-sql-value) value resolver). Therefore, the [List item](/v1/docs/en/core-list-item-resolver) value resolver is used to identify the first item whose `username` field identifies the already deleted user account as a *fallback* value. | ![images/download/attachments/177909604/image-2024-9-3_9-13-52-version-1-modificationdate-1725347632469-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image-2024-9-3_9-13-52-version-1-modificationdate-1725347632469-api-v2.png) | | --- | --- |