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

Unpredictable/incorrect results for ST_Contains with Polygon_2D and Point_2D geometries #434

Open
ammojamo opened this issue Oct 18, 2024 · 0 comments

Comments

@ammojamo
Copy link

DuckDB Version: v1.1.2 f680b7d08f
MacOS 14.4.1 (M2)
Installed via Homebrew

I have uploaded a sample database here which is needed to reproduce the problem: https://www.dropbox.com/s/up7uvgdz15924dr/test.tar.xz?dl=0

This issue is only reproducible with a persistent database, not an in-memory database

Steps to reproduce issue:

LOAD spatial;
# Import sample database
IMPORT DATABASE 'test';

# Import doesn't work with Point_2D columns (I have filed a separate issue about that), so we create it now:
ALTER TABLE test ADD COLUMN location Point_2D;
UPDATE test SET location = ST_Point2D(lon, lat);

# The following query should return no results, but it returns 98 rows
SELECT id
FROM test
WHERE list_contains(area_layer_ids, 2)
AND ST_Contains('POLYGON ((145.16503 -37.92571, 145.24262 -37.86881, 145.30991 -37.91, 145.31163 -37.92869, 145.16503 -37.92571))'::Geometry::Polygon_2D, location);

# If I change 'location' to ST_Point2D(lon,lat), the query works as expected (returns zero rows):
SELECT id
FROM test
WHERE list_contains(area_layer_ids, 2)
AND ST_Contains('POLYGON ((145.16503 -37.92571, 145.24262 -37.86881, 145.30991 -37.91, 145.31163 -37.92869, 145.16503 -37.92571))'::Geometry::Polygon_2D, ST_Point2D(lon,lat));

I tried to come up with a smaller reproducible example, e.g. removing list_contains from the query, or using a smaller dataset, but this seemed to prevent the bug from being triggered.

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

1 participant