Functions

Define a function for counting reviews given a user name:

Copy
CREATE FUNCTION review_count(name: str) -> int64
USING EdgeQL $$
    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 EdgeQL $$ SELECT 'my_name_' ++ name $$;
CREATE
Copy
db> 
... 
CREATE FUNCTION make_name(name: int64) -> str
USING EdgeQL $$ SELECT 'my_name_' ++ <str>name $$;
CREATE
Copy
q> 
SELECT make_name('Alice');
{'my_name_Alice'}
Copy
q> 
SELECT make_name(42);
{'my_name_42'}
Light
Dark
System