Skip to main content
Version: 0.1.0

System Functions

Functions for querying system information, session details, and RaisinDB-specific authentication state.

Standard System Functions

VERSION

Return the RaisinDB server version.

VERSION()TEXT
SELECT VERSION();
-- Result: 'RaisinDB 0.1.0'

CURRENT_SCHEMA

Return the current schema name.

CURRENT_SCHEMA()TEXT
SELECT CURRENT_SCHEMA();

CURRENT_DATABASE

Return the current database name.

CURRENT_DATABASE()TEXT
SELECT CURRENT_DATABASE();

CURRENT_USER

Return the current user name.

CURRENT_USER()TEXT
SELECT CURRENT_USER();

SESSION_USER

Return the session user name.

SESSION_USER()TEXT
SELECT SESSION_USER();

CURRENT_CATALOG

Return the current catalog name.

CURRENT_CATALOG()TEXT
SELECT CURRENT_CATALOG();

RaisinDB Authentication Functions

RAISIN_CURRENT_USER

Return the current RaisinDB authenticated user.

RAISIN_CURRENT_USER()TEXT
SELECT RAISIN_CURRENT_USER();

RAISIN_AUTH_CURRENT_USER

Return detailed information about the currently authenticated user.

RAISIN_AUTH_CURRENT_USER() → JSONB
SELECT RAISIN_AUTH_CURRENT_USER();

RAISIN_AUTH_CURRENT_WORKSPACE

Return the current workspace context for the authenticated user.

RAISIN_AUTH_CURRENT_WORKSPACE()TEXT
SELECT RAISIN_AUTH_CURRENT_WORKSPACE();

RAISIN_AUTH_HAS_PERMISSION

Check if the current user has a specific permission.

RAISIN_AUTH_HAS_PERMISSION(permission)BOOLEAN
ParameterTypeDescription
permissionTEXTPermission name to check
SELECT RAISIN_AUTH_HAS_PERMISSION('write');
SELECT RAISIN_AUTH_HAS_PERMISSION('admin');

RAISIN_AUTH_GET_SETTINGS

Retrieve authentication settings.

RAISIN_AUTH_GET_SETTINGS() → JSONB
SELECT RAISIN_AUTH_GET_SETTINGS();

RAISIN_AUTH_UPDATE_SETTINGS

Update authentication settings.

RAISIN_AUTH_UPDATE_SETTINGS(settings) → JSONB
ParameterTypeDescription
settingsJSONBNew settings to apply
SELECT RAISIN_AUTH_UPDATE_SETTINGS('{"require_mfa": true}');

RAISIN_AUTH_ADD_PROVIDER

Add an authentication provider.

RAISIN_AUTH_ADD_PROVIDER(provider_config) → JSONB
ParameterTypeDescription
provider_configJSONBProvider configuration
SELECT RAISIN_AUTH_ADD_PROVIDER('{
"type": "oauth2",
"name": "github",
"client_id": "..."
}');

RAISIN_AUTH_UPDATE_PROVIDER

Update an existing authentication provider.

RAISIN_AUTH_UPDATE_PROVIDER(provider_name, config) → JSONB
ParameterTypeDescription
provider_nameTEXTName of the provider to update
configJSONBUpdated configuration
SELECT RAISIN_AUTH_UPDATE_PROVIDER('github', '{"enabled": false}');

RAISIN_AUTH_REMOVE_PROVIDER

Remove an authentication provider.

RAISIN_AUTH_REMOVE_PROVIDER(provider_name)BOOLEAN
ParameterTypeDescription
provider_nameTEXTName of the provider to remove
SELECT RAISIN_AUTH_REMOVE_PROVIDER('github');

Type Membership Functions

Fast checks against a node's materialized type sets. Every node is stamped on write with its effective mixins and supertypes, so these are simple membership tests — no schema resolution happens at query time. See Using Mixins.

HAS_MIXIN

True if the node carries the given mixin (type-declared, transitively).

HAS_MIXIN(properties, mixin_name)BOOLEAN
ParameterTypeDescription
propertiesJSONBThe node's properties column
mixin_nameTEXTMixin name to test, e.g. 'myapp:SEO'
SELECT * FROM 'workspace' WHERE HAS_MIXIN(properties, 'myapp:SEO');

IS_A

True if the node "is a" given type — its node_type, any EXTENDS ancestor, or any mixin.

IS_A(properties, type_name)BOOLEAN
ParameterTypeDescription
propertiesJSONBThe node's properties column
type_nameTEXTType name to test, e.g. 'myapp:Article'
SELECT * FROM 'workspace' WHERE IS_A(properties, 'myapp:Article');

Lock & Inventory Functions

Atomic locks & inventory from SQL. These call the same backend as the function/HTTP/WS surfaces. They require the [locks] subsystem to be enabled and an authenticated, non-anonymous session (a held lock is a denial-of-service vector); the requested TTL is capped at 5 minutes. Keys are scoped to the current tenant / repository / branch.

RAISIN_TRY_ACQUIRE

Try once to acquire a lease-lock on an arbitrary key. Returns JSON with the result and a monotonically increasing fence token.

RAISIN_TRY_ACQUIRE(key, ttl_ms) → JSONB
ParameterTypeDescription
keyTEXTArbitrary lock key, e.g. 'seat:AA123:14A'
ttl_msBIGINTLease duration in milliseconds (auto-expires; max 300000)
SELECT RAISIN_TRY_ACQUIRE('seat:AA123:14A', 5000);
-- {"acquired": true, "key": "seat:AA123:14A", "token": 42, "expires_at_ms": 1750000000000}
-- or, if currently held by someone else:
-- {"acquired": false}

RAISIN_RELEASE

Release a lock held with the given fence token. Returns false if the lock was already gone or held by someone else.

RAISIN_RELEASE(key, token)BOOLEAN
SELECT RAISIN_RELEASE('seat:AA123:14A', 42);

RAISIN_RENEW

Extend the lease on a held lock. Returns false if the lease was already lost.

RAISIN_RENEW(key, token, ttl_ms)BOOLEAN
SELECT RAISIN_RENEW('seat:AA123:14A', 42, 5000);

RAISIN_CLAIM

Atomically claim n units from an inventory pool, seeding it to capacity the first time it is touched. Never oversells.

RAISIN_CLAIM(pool, n, capacity) → JSONB
ParameterTypeDescription
poolTEXTInventory pool name, e.g. 'flight:AA123'
nBIGINTUnits to claim
capacityBIGINTPool size (used only on first touch)
SELECT RAISIN_CLAIM('flight:AA123', 1, 180);
-- {"claimed": true, "remaining": 179} (or {"claimed": false} when sold out)

RAISIN_RELEASE_CLAIM

Return n units to a pool. Returns the new remaining count.

RAISIN_RELEASE_CLAIM(pool, n)BIGINT
SELECT RAISIN_RELEASE_CLAIM('flight:AA123', 1);

Fencing a write (the secure pattern)

The fence token lets a guarded write reject a stale holder. Record the token on the protected row and only update when your token is newer — a standard compare-and-swap UPDATE whose affected-row count tells you if you won:

-- 1) acquire → token (say 42)
-- 2) guarded write: succeeds only if no newer holder has written
UPDATE 'flights' SET properties = $1::jsonb
WHERE path = '/AA123/14A' AND properties->>'fence'::String < '42';
-- 0 rows affected ⇒ a newer holder won; back off.

Notes

  • Standard system functions follow PostgreSQL conventions
  • CURRENT_USER() and SESSION_USER() may differ when impersonation is used
  • RAISIN_AUTH_* functions are specific to RaisinDB's authentication system
  • Authentication management functions require appropriate admin permissions
  • All functions return NULL if the requested information is not available