Skip to content

PostgresStorageAdapter.js: postgis version aware use of distance sphere function (GeoPoint distance calculation) #6441

Closed
@xeaon

Description

@xeaon

Issue Description

If you use postgresql as database and need to calculate distances of GeoPoint objects, you obviously need postgis. In postgis version > 2.2.0 the function ST_Distance_Sphere was renamed to ST_DistanceSphere which causes the Postgres Storage Adapter to fail here:

`ST_distance_sphere($${index}:name::geometry, POINT($${index +

`ST_distance_sphere($${index}:name::geometry, POINT($${index +

`ST_distance_sphere($${index}:name::geometry, POINT($${index +

It should be possible to build these queries based on the postgis version by actually quering the version. I'll try to implement a fix but if anyone else has an elegant way to solve it, please do it :)

Steps to reproduce

  1. pull postgis/postgis or install postgis from source
  2. use postgis instead of mongo
  3. add a GeoPoint column to your class and try to query a near location

Expected Results

actual near locations

Actual Outcome

query fails with an internal error

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 3.10.0 (parseplatform/parse-server
      image drom dockerhub)
    • Operating System: ubuntu
    • Hardware: docker container
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): localhost
  • Database

    • MongoDB PostgreSQL version: POSTGIS="3.0.0 r17983" [EXTENSION] PGSQL="120" (postgis/postgis image from dockerhub)
    • Hardware: docker container
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): localhost

Logs/Trace

error: Parse error: error: function st_distance_sphere(geometry, geometry) does not exist

{"code":1,"stack":"Error: error: function st_distance_sphere(geometry, geometry) does not exist\n    at /parse-server/lib/Controllers/DatabaseController.js:1194:21\n    at processTicksAndRejections (internal/process/task_queues.js:94:5)"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions