Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgrex expected a binary, got %Geo.Point #70

Closed
Virviil opened this issue Jun 10, 2017 · 9 comments
Closed

Postgrex expected a binary, got %Geo.Point #70

Virviil opened this issue Jun 10, 2017 · 9 comments

Comments

@Virviil
Copy link

Virviil commented Jun 10, 2017

This query is working:

INSERT INTO "bookmarks" ("address","bookmark_type","description","is_active","is_delete","latlng","tag","uid","inserted_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) RETURNING "id" ["adi", "private", "testing", true, false, %Geo.Point{coordinates: {26.7885576, 75.8270401}, srid: 4326}, "test1 test2 test3", "2ffce5f2e79a4f8c917fc58591260cdb80011f6d", {{2017, 6, 10}, {17, 30, 46, 127816}}, {{2017, 6, 10}, {17, 30, 46, 134318}}]

while this one returns error:

SELECT b0."id", b0."uid", b0."tag", b0."description", b0."address", b0."bookmark_type", b0."is_active", b0."is_delete", b0."latlng", b0."inserted_at", b0."updated_at" FROM "bookmarks" AS b0 WHERE (b0."bookmark_type" = 'public') AND (ST_Within(b0."latlng",ST_Buffer($1, $2, 8))) AND ((b0."is_active" = TRUE) AND (b0."is_delete" != TRUE)) ORDER BY b0."updated_at" DESC LIMIT $3 OFFSET $4 [%Geo.Point{coordinates: {26.7885576, 75.8270401}, srid: 4326}, 1.0, 10, 0]

So, I'm totally confused. It seems to me that potgrex in both cases should either work or not work - because either cast or not cast to binary.

May be I'm mising something in the configuration, or you can navigate me where should I dig deeper to see where is the problem?

@bryanjos
Copy link
Contributor

@Virviil I'm not sure either with the information given. It may be a configuration problem. Are the two queries run in the same mix environment? Is there a simpler query you could run that shows it working or not working?

@Virviil
Copy link
Author

Virviil commented Jun 11, 2017

Yep, both queries in one session of mix phoenix.server

@Virviil
Copy link
Author

Virviil commented Jun 12, 2017

I can provide you any information, just don't know which

@bryanjos
Copy link
Contributor

@Virviil is that the query the Ecto runs? If so could you show me your Ecto query if possible?

@Virviil
Copy link
Author

Virviil commented Jun 15, 2017

No problem.

SELECT Request

Repo.all(
    from b in Bookmark,
    where: b.bookmark_type == "public",
    where: st_within(b.latlng, st_buffer(^point, ^radius, 8)),
    where: b.is_active == true and b.is_delete != true,
    order_by: [desc: b.updated_at],
    offset: ^offset,
    limit: ^limit,
    select: b
)

INSERT Request

Just populating changeset, one of the params is %Geo.Point{}, and then Repo.insert

@bryanjos
Copy link
Contributor

@Virviil sorry for the delayed response. I'm not sure what the issue is from looking at it. As far as I can tell from the SQL and from the Ecto query, it all looks correct. It may be a bug here, but not sure. Could also be something with Postgrex, but let's make sure first. What happens if you replace the called to st_within and st_buffer with fragments that call the underlying PostGIS functions?

@Virviil
Copy link
Author

Virviil commented Jul 1, 2017 via email

@bryanjos
Copy link
Contributor

bryanjos commented Jul 1, 2017

Glad you were able to find a workaround. When I have some time I'll try to reproduce this and if I can I'll try to fix it.

@bryanjos
Copy link
Contributor

Going to close this since there was a workaround and nothing has came up since

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants