Skip to Content
🚀 KalamDB v0.3.0-alpha2 is out — Learn more
SQL ReferenceImpersonation

Impersonation

Impersonation allows service accounts and administrators to execute SQL statements on behalf of another user. This is essential for bot interactions and service-side operations.

EXECUTE AS USER

EXECUTE AS USER '<username>' ( <single_statement> );

Rules

  1. The wrapper must contain exactly one SQL statement
  2. The username must be single-quoted
  3. Legacy inline ... AS USER 'name' syntax is not supported

Examples

Query as a specific user:

EXECUTE AS USER 'admin' ( SELECT * FROM app.messages WHERE conversation_id = 42 );

Insert on behalf of a service bot:

EXECUTE AS USER 'service_bot' ( INSERT INTO app.messages (conversation_id, sender, role, content) VALUES (42, 'service_bot', 'assistant', 'Processing complete') );

Delete as admin:

EXECUTE AS USER 'admin' ( DELETE FROM app.messages WHERE id = 123 );

Use Cases

ScenarioDescription
AI bot responsesService account inserts assistant messages into user conversations
Admin operationsDBA performs maintenance on user tables
TestingSimulate user actions in development
Audit trailsActions are logged under the impersonated user
Last updated on