Integrating PostGIS to an existing database.
# help-and-questions
b
Hey everyone, New to Supabase here but I assume this is pretty straightforward. I have a database that already has a latitude and longitude column and I want to be able to sort them by location. I already have PostGIS enabled, so is there an SQL command I can run to copy the data from these two columns and add them to a new location column?
v
in general you just use an update,
update mytable set newcol=oldcol
. The specifics of what you need depends on what the column type of your new column is. We can infer that the lat/lon are floats.
b
Yes they’re both floats. How do take “col1” + “col2” and combine into a new column?
g
Have you googled
postgis convert lat lon columns to single
or something like that. I see lots of hits. Postgis supports different types of columns to depending on things like using geometry or geography, etc. https://gis.stackexchange.com/questions/145007/creating-geometry-from-lat-lon-in-table-using-postgis First hit I got, there were many
I use geometry with a point,4326 column. It works well for location on map, and is faster than geography, but you need to see the tradeoffs of that for large distances depending on what you are doing. I pass the data in from the clients browser location data using...
note.location = "SRID=4326;POINT(" + geo.coords.long + " " + geo.coords.lat + ")"