Query Context Parameters
The Portal supplies a set of context parameters that describe the
user running a query. You reference them in Data Source
and block query SQL using the named-parameter
syntax :<name>, and the Portal binds them to the current user's session
at execution time.
Because these values come from the authenticated session — not from anything the user types — they are well suited to row-level security: a query can filter its results to only the rows a given user, or their group memberships, are allowed to see. The user cannot override them.
Tip
Type : in the SQL editor to see the available parameters in
auto-complete.
Available parameters
| Parameter | Type | Description |
|---|---|---|
:__current_user_id |
string | The current user's unique ID. |
:__current_user_username |
string | The current user's username. |
:__current_user_fullname |
string | The current user's full name. |
:__current_user_email |
string | The current user's email address. |
:__current_user_group_names |
array of strings | The names of every group the user belongs to. |
:__current_user_group_names_json |
string | The same group names encoded as a JSON array string. |
Scalar parameters
The four scalar parameters substitute directly into a query as bound values:
SELECT *
FROM orders
WHERE owner_email = :__current_user_email
SELECT *
FROM activity_log
WHERE user_id = :__current_user_id
Group parameters
Group membership is exposed in two forms so you can filter against the user's groups on any supported database. Use the form your database understands:
:__current_user_group_names— a native array/list. Use it where the database supports array or list-valued parameters.:__current_user_group_names_json— a JSON array string. Use it where array parameters are not supported (SQL Server, MySQL), with the database's JSON functions.
PostgreSQL
:__current_user_group_names binds as a text[] array. Use = ANY(...)
(works on all PostgreSQL drivers):
SELECT *
FROM reports
WHERE owning_group = ANY(:__current_user_group_names)
Snowflake
:__current_user_group_names works with an IN list:
SELECT *
FROM reports
WHERE owning_group IN (:__current_user_group_names)
SQL Server
Array parameters are not supported. Use the JSON form with OPENJSON:
SELECT *
FROM reports
WHERE owning_group IN (
SELECT value FROM OPENJSON(:__current_user_group_names_json)
)
MySQL
Array parameters are not supported. Use the JSON form with
JSON_CONTAINS (or JSON_TABLE):
SELECT *
FROM reports
WHERE JSON_CONTAINS(
:__current_user_group_names_json, JSON_QUOTE(owning_group)
)
Deprecated short codes
Earlier Portal versions exposed these values under unprefixed short names. The short codes still resolve at runtime, but they are reported as warnings in the SQL editor. Migrate to the prefixed parameters above.
| Deprecated | Replacement |
|---|---|
:id |
:__current_user_id |
:username |
:__current_user_username |
:fullname |
:__current_user_fullname |
:email |
:__current_user_email |
:groups |
:__current_user_group_names |
:groups is not identical to :__current_user_group_names
:groups binds as a tuple with a trailing NULL appended (so an
IN clause is never empty), and is used as ... IN :groups without
surrounding parentheses. It is not supported on every driver — for
example, the PostgreSQL asyncpg driver cannot bind it. The
replacement :__current_user_group_names is a plain array with no
trailing NULL. When migrating, also update the surrounding SQL to
the array patterns shown in Group parameters.