Type to search…

Function

You can call stored procedures as a "Remote Procedure Call".

Introduction

Database Functions

Functions are a fancy way of saying that you can put some logic into your database then call it from anywhere.

It’s especially useful when the logic rarely changes – like password resets and updates.

Database function and can be called remotely using the REST and GraphQL API.

Simple functions

Let’s create a basic Database Function which returns a string “hello world”.

sqlc
reate or replace function hello_world()
returns text
language sql
as $$
  select 'hello world';
$$;

When naming your functions, make the name of the function unique as overloaded functions are not supported.

After the Function is created, we have several ways of “executing” the function.

Directly inside the database using SQL,

sql
select hello_world();

Or with the Kotlin library (rpc):

kotlin
val data = supabase.postgrest.rpc("hello_world")

When calling rpc with parameters, you have to provide a serializable value in the function parameter.

kotlin
val rpcParams = City(name = "The Shire")
supabase.postgrest.rpc("echo_city", rpcParams)

You're reading a preview.

Sign in with Google to read the full page. A Google account includes 5 free pages in total; students and teachers read their course pages without limit.

Sign in