Custom types, arrays and PostGIS are frequently presented together since geospatial data is often complex and multidimensional.
It’s therefore recommend to first quickly scan the content in Custom Types, Arrays and JSON
PowerSync integrates well with PostGIS and provides tools for working with geo data.
In Supabase, the PostGIS extension needs to be added to your project to use this type. Run the following command in the SQL editor to include the PostGIS extension:
The geography
and geometry
types are now available in your Postgres.
This example builds on the To-Do List demo app in our Supabase integration guide.
todos
tableNote the following:
Custom type: Specify the value for the address
column by wrapping the value in single quotes and comma separate the different location_address properties.
'("1000 S Colorado Blvd.","Denver","CO",80211)'
Array: Specify the value of the contact_numbers
column, by surrounding the comma-separated array items in curly braces.
'{000-000-0000, 000-000-0000, 000-000-0000}'
PostGIS: Specify the value of the location
column by using the st_point
function and pass in the latitude and longitude
st_point(39.742043, -104.991531)
These data types show up as follows when querying from the PowerSync Dashboard’s SQL Query editor:
location |
---|
0101000020E6100000E59CD843FBDE4340E9818FC18AC052C0 |
This is Postgres’ internal binary representation of the PostGIS type.
Note:
TEXT
in the AppSchema. The Postgres PostGIS capabilities are not available because the PowerSync SDK uses SQLite, which only has a limited number of types. This means that everything is replicated into the SQLite database as TEXT values.The data looks exactly how it’s stored in the Postgres database i.e.
(1000 S Colorado Blvd.,Denver,CO,80211)
{000-000-0000, 000-000-0000, 000-000-0000}
geography
type is transformed into an encoded form of the value.
st_point(39.742043, -104.991531)
then it is shown as 0101000020E6100000E59CD843FBDE4340E9818FC18AC052C0
Example use case: Extract x (long) and y (lat) values from a PostGIS type, to use these values independently in an application.
Currently, PowerSync supports the following functions that can be used when selecting data in your sync rules: Operators and Functions
ST_AsGeoJSON
ST_AsText
ST_X
ST_Y
IMPORTANT NOTE: These functions will only work if your Postgres instance has the PostGIS extension installed and you’re storing values as type geography
or geometry
.