Declaring functions

Define a function for counting reviews given a user name:

  1. create function review_count(name: str) -> int64
  2. using (
  3. with module default
  4. select count(
  5. (
  6. select Review
  7. filter .author.name = name
  8. )
  9. )
  10. )

Drop a user-defined function:

  1. drop function review_count(name: str);

Define and use polymorphic function:

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

See also

Schema > Functions

SDL > Functions

DDL > Functions

Reference > Function calls

Introspection > Functions