Skip to content

geo querys and sorting by distance #5390

Answered by dshukertjr
Crey443 asked this question in Questions
Discussion options

You must be logged in to vote

Yes, Postgres supports geo queries much better than Firestore!

In order to query data and order it by distance, you would first need to enable postgis extension in your Supabase project.

Your table could look something like this:

create table if not exists public.videos (
    id uuid not null primary key DEFAULT uuid_generate_v4 (),
    created_at timestamp with time zone default timezone('utc' :: text, now()) not null,
    description varchar(320) not null,
    location geography(POINT) not null
);

The key here is the location column with geography(POINT) type which represents a geographic location on earth.

Then you can create a Postgres function like this:

create or replace function te…

Replies: 5 comments 25 replies

Comment options

You must be logged in to vote
2 replies
@Crey443
Comment options

@wiesson
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
23 replies
@phillipmohr
Comment options

@mijorus
Comment options

@organicnz
Comment options

@dshukertjr
Comment options

@incrediblezayed
Comment options

Answer selected by dshukertjr
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet