Skip to Content
Server FunctionsCreate & Call Procedures

KalamDB Server Procedures

Run KalamDB server logic next to your data and call it from SQL. Create the app schema first and use an account with routine creation privileges.

Create a KalamDB function or procedure

SQL
CREATE OR REPLACE FUNCTION app.echo(msg TEXT)RETURNS TEXTLANGUAGE JAVASCRIPTAS $$  return input.msg;$$; SELECT app.echo('hello');

Expect a value of hello. Function arguments arrive in the named input object. In 0.8, a function declares RETURNS and is invoked with SELECT. A procedure uses CALL and can declare OUT or INOUT parameters instead:

SQL
CREATE OR REPLACE PROCEDURE app.bump(INOUT value INT, OUT doubled INT)LANGUAGE PLPGSQLAS $$BEGIN  doubled := value * 2;  value := value + 1;END$$; CALL app.bump(7);

Expect value to be 8 and doubled to be 14.

Call it from your application

Use your SDK’s SQL query API to execute CALL, or use the generated function client from schema generation and deployment. Procedures also have an HTTP invocation endpoint.

Common mistakes

Do not use the older CREATE PROCEDURE … RETURNS syntax in 0.8. New routines are not executable by everyone. Grant execution intentionally before calling as a normal application user. Inline JavaScript runs immediately; project TypeScript needs compilation and deployment. Do not send ctx, actor identity, or transaction context from the client.

Next step

Send background work through topics →

Reference: Procedure permissions, topic triggers, and scheduled jobs.