Skip to content

how to use extensions #2195

Discussion options

You must be logged in to vote

Hey @atiframlee,

Here's an example using earthdistance's <@> operator:

-- create this function on the db
create or replace function distance(long1 float8, lat1 float8, long2 float8, lat2 float8) returns float8 as $$
  select POINT(long1, lat1) <@> POINT(long2, lat2) as distance;    
$$ language sql;
-- suit this to use your cities table
// call it through supabase rpc: https://supabase.io/docs/reference/javascript/rpc
const { data, error } = await supabase
  .rpc('distance', {long1: -81.3927381, lat1: 30.2918842, long2: -87.6473133, lat2: 41.8853881})

console.log(data);
873.203527399339

In general, you can expose any SQL functionality with a function and call it through RPC.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by steve-chavez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants