stefanoa0

stefanoa0

Geo.Postgis with CockroachDB - (Postgrex.Error) ERROR 42883 (undefined_function) st_contains()

Hello everyone, I hope you are well.

I’m migrating from PostgreSQL to CockroachDB and everything was going well until I came across the following error using the Geo.Postgis lib:

** (Postgrex.Error) ERROR 42883 (undefined_function) st_contains(): unknown signature: st_buffer(geometry, geometry) (desired <geometry>)

Here is the specific where snippet:

|> where(
      [u],
      st_contains(st_buffer(st_set_srid(st_make_point(^lng, ^lat), 4326), ^distance), u.geo_point)
    )

I tried changing to a fragment function with the string:

fragment("ST_Contains(ST_Buffer(ST_SetSRID(ST_MakePoint($2, $3), 4326), $4), u0.geo_point)", lng, lat, distance)

But the same error happened

Has anyone had a similar error?

Thanks for your time!

Marked As Solved

stefanoa0

stefanoa0

Hello

Thanks for this informations, but the CockroachDB is compatible with PostgresSQL, as described:

[> CockroachDB supports the PostgreSQL wire protocol and the majority of PostgreSQL syntax. This means that existing applications built on PostgreSQL can often be migrated to CockroachDB without changing application code.]

So, the migrations was easy and all the queries are running very well, but that query who uses the Postgis functions needed to changed, I had to cast the distance to float and It’s works!

|> where(
      [u],
      st_contains(st_buffer(st_set_srid(st_make_point(^lng, ^lat), 4326), ^fragment("Cast(? as FLOAT)", distance), u.geo_point)
    )

So, thanks for your help and time!

Also Liked

pdgonzalez872

pdgonzalez872

hi @stefanoa0 , welcome to ElixirForum!

So, ST_Contains is not native to Postgres, it comes from the postgis extension. You can use the function when you install an extension. Here is the documentation for the function: https://postgis.net/docs/manual-3.4/ST_Contains.html.

The lib you are using is a wrapper around the postgis extension, that’s why your fragment didn’t work. Postgres just doesn’t know a function with that name.

Here is a link that will help you migrate that specific functionality over: How we built scalable spatial data and spatial indexing in CockroachDB

I love Postgres, including the postgis library. Sad to see you migrate away from Postgres, but good luck nonetheless!

pdgonzalez872

pdgonzalez872

Great!

Thanks for this informations, but the CockroachDB is compatible with PostgresSQL, as described:

Well, we saw that in this case it wasn’t a 1 to 1 since you had to refactor that function call. BUT, on CockRoachDB’s defense, postgis is not part of core, it’s an extension to Postgres even though it is the de-facto way of dealing with spacial data in Postgres. So, their claim could still very well be valid.

So, thanks for your help and time!

You are welcome!

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement