---
title: SqlAttributesFilter
description: This filter uses synchronous architecture. Accessing the filter target triggers a call to the database that blocks the executing thread until the database responds.
component: pinggateway
version: 2023.11
page_id: pinggateway:reference:SqlAttributesFilter
canonical_url: https://docs.pingidentity.com/pinggateway/2026/reference/SqlAttributesFilter.html
llms_txt: https://docs.pingidentity.com/pinggateway/llms.txt
docs_for_agents: https://developer.pingidentity.com/build-with-ai/docs-for-agents.md
revdate: 2025-06-03T11:21:31Z
superseded_by: https://docs.pingidentity.com/pinggateway/2026/reference/SqlAttributesFilter.html
section_ids:
  SqlAttributesFilter-usage: Usage
  SqlAttributesFilter-properties: Properties
  SqlAttributesFilter-example: Example
  SqlAttributesFilter-moreinfo: More information
---

# SqlAttributesFilter

|   |                                                                                                                                                                                                                                                                                                                                                                                     |
| - | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|   | This filter uses synchronous architecture. Accessing the filter `target` triggers a call to the database that blocks the executing thread until the database responds.Consider the performance impact of this filter, especially for deployments with a small number of gateway units (therefore, a small number of executing threads) and a long execution time for the JDBC call. |

Executes a SQL query through a prepared statement and exposes its first result. Parameters in the prepared statement are derived from expressions. The query result is exposed in an object whose location is specified by the `target` expression. If the query yields no result, then the resulting object is empty.

The execution of the query is performed lazily; it does not occur until the first attempt to access a value in the target. This defers the overhead of connection pool, network and database query processing until a value is first required. This also means that the parameters expressions is not evaluated until the object is first accessed.

## Usage

```json
{
  "name": string,
  "type": "SqlAttributesFilter",
   "config": {
     "dataSource": JdbcDataSource reference,
     "preparedStatement": configuration expression<string>,
     "parameters": [ runtime expression<string>, ... ],
     "target": lvalue-expression
   }
}
```

## Properties

* `"dataSource"`: *JdbcDataSource [reference](preface.html#definition-reference), required*

  |   |                                                                                                                                                                                                                                                                               |
  | - | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  |   | `dataSource` as a JNDI lookup name is deprecated; use `dataSource` as a JdbcDataSource configuration object instead. For more information, refer to the [Deprecated](https://docs.pingidentity.com/pinggateway/release-notes/deprecated.html) section of the *Release Notes*. |

  The JdbcDataSource to use for connections. Configure JdbcDataSource as described in [JdbcDataSource](MiscellaneousConfigurationObjects.html#JdbcDataSource).

* `"preparedStatement"`: *configuration expression<[string](preface.html#definition-string)>, required*

  The parameterized SQL query to execute, with `?` parameter placeholders.

* `"parameters"`: *array of runtime expressions\<strings>, optional*

  The parameters to evaluate and include in the execution of the prepared statement.

  See also [Expressions](Expressions.html#Expressions).

* `"target"`: *<[lvalue-expression](preface.html#definition-lvalue-expression)>, required*

  Expression that yields the target object containing the query results. For example, `${target.sql.queryresult}`.

  Access to `target` triggers a call to the database that blocks the executing thread until the database responds.

  See also [Expressions](Expressions.html#Expressions).

## Example

Using the user's session ID from a cookie, query the database to find the user logged in and set the profile attributes in the attributes context:

```json
{
        "name": "SqlAttributesFilter",
        "type": "SqlAttributesFilter",
        "config": {
              "target": "${attributes.sql}",
              "dataSource": "java:comp/env/jdbc/mysql",
              "preparedStatement": "SELECT f.value AS 'first', l.value AS 'last', u.mail AS 'email', GROUP_CONCAT(CAST(r.rid AS CHAR)) AS 'roles' FROM sessions s INNER JOIN users u ON ( u.uid = s.uid AND u.status = 1 ) LEFT OUTER JOIN profile_values f ON ( f.uid = u.uid AND f.fid = 1 ) LEFT OUTER JOIN profile_values l ON ( l.uid = u.uid AND l.fid = 2 ) LEFT OUTER JOIN users_roles r ON ( r.uid = u.uid ) WHERE (s.sid = ? AND s.uid <> 0) GROUP BY s.sid;",
              "parameters": [ "${request.cookies[keyMatch(request.cookies,'JSESSION1234')][0].value}" ]
         }
 }
```

Lines are folded for readability in this example. In your JSON, keep the values for `"preparedStatement"` and `"parameters"` on one line.

## More information

[org.forgerock.openig.sql.SqlAttributesFilter](../_attachments/apidocs/org/forgerock/openig/sql/SqlAttributesFilter.html)
