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

Using st_d_within with Nullable<Geography> #21

Closed
GioF opened this issue Dec 19, 2023 · 4 comments
Closed

Using st_d_within with Nullable<Geography> #21

GioF opened this issue Dec 19, 2023 · 4 comments

Comments

@GioF
Copy link

GioF commented Dec 19, 2023

error[E0277]: the trait bound `diesel::sql_types::Nullable<postgis_diesel::sql_types::Geography>: GeoType` is not satisfied
   --> src/models/hardware.rs:113:42
    |
113 |                     query = query.filter(st_d_within(location, second_point, radius));
    |                                          ^^^^^^^^^^^ the trait `GeoType` is not implemented for `diesel::sql_types::Nullable<postgis_diesel::sql_types::Geography>`
    |
    = help: the following other types implement trait `GeoType`:
              Geometry
              postgis_diesel::sql_types::Geography
note: required by a bound in `st_d_within`
   --> /home/gio/.cargo/registry/src/github.com-1ecc6299db9ec823/postgis_diesel-2.2.1/src/functions.rs:99:23
    |
99  |     fn st_d_within<G: GeoType>(left: G, right: G, distance: Double) -> Bool;
    |                       ^^^^^^^ required by this bound in `st_d_within`

The error above appears when attempting to call st_d_within with a column of type Nullable.

@vitaly-m
Copy link
Owner

vitaly-m commented Jan 3, 2024

Hello @GioF, my understanding is that functions like that are working properly only in case parameters are not null, otherwise, in case any geometry is NULL it will return NULL, which is kind of unexpected anyway and comparison with FALSE anyway will be failed.

Here is an example of requests and results:

select ST_DWithin(track, track, 0) from laps;

result:

st_dwithin|
----------+
false     |
true      |
select ST_DWithin(track, null, 0) from laps;

result with nulls:

st_dwithin|
----------+
          |
          |

And another example with result = 0:

select count(*) from laps where ST_DWithin(track, null, 0);

Maybe it is possible to check the null value on code level and pass only not null geometries? But also maybe it should be supported like it is supported on PG side, with nullable parameters and nullable result, I will think about how to do that, or you can create a PR for that.

vitaly-m added a commit that referenced this issue Jan 7, 2024
feat: #21 support functions with nullable parameters and return type
@vitaly-m
Copy link
Owner

vitaly-m commented Jan 7, 2024

Functions which support nullable parameters are implemented in separate module functions_nullable, this is done because return type should have also being changed and it could lead to backward incompatible changes. Example of usage in d_within_test

Implemented in v2.3.0.

@vitaly-m vitaly-m closed this as completed Jan 7, 2024
@GioF
Copy link
Author

GioF commented Jan 7, 2024

Sadly i couldn't take a look on how to implement this because i was busy with personal matters, but i will look into the code to learn a bit. Either way, thanks!

@rj76
Copy link

rj76 commented Jan 7, 2024

This is great! Also a big thank you from me.

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

No branches or pull requests

3 participants