Light
Dark
System
v4latest
v5dev
v4latest
v3
v2
v1

Declaring functions

Define a function for counting reviews given a user name:

Copy
create function review_count(name: str) -> int64
using (
    with module default
    select count(
        (
            select Review
            filter .author.name = name
        )
    )
)

Drop a user-defined function:

Copy
drop function review_count(name: str);

Define and use polymorphic function:

Copy
db> 
... 
create function make_name(name: str) -> str
using ('my_name_' ++ name);
CREATE FUNCTION
Copy
db> 
... 
create function make_name(name: int64) -> str
using ('my_name_' ++ <str>name);
CREATE FUNCTION
Copy
q> 
select make_name('Alice');
{'my_name_Alice'}
Copy
q> 
select make_name(42);
{'my_name_42'}
Light
Dark
System

We use ChatGPT with additional context from our documentation to answer your questions. Not all answers will be accurate. Please join our Discord if you need more help.