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

Error thrown when trying to create a GEOMETRY column in postgis, from duckdb #482

Open
CGenie opened this issue Jan 17, 2025 · 4 comments
Open

Comments

@CGenie
Copy link

CGenie commented Jan 17, 2025

Hello,

Here's what I do:

LOAD spatial
attach 'host=localhost ...' AS db (TYPE postgres);

CREATE TABLE db.points (name varchar, pt geometry);

However, I get:

INTERNAL Error: Unsupported logical type for RemoveAlias
This error signals an assertion failure within DuckDB. This usually occurs due to unexpected conditions or errors in the program's logic.
For more information, see https://duckdb.org/docs/dev/internal_errors

Any ideas if this is solvable?

@CGenie
Copy link
Author

CGenie commented Jan 17, 2025

BTW, when I pre-create that table on the PostGIS side, I'm able to insert data like this, without error:

INSERT INTO db.points (SELECT name, ST_AsText(ST_GeomAsHEXEWKB(pt)) AS pt FROM my_other_source);

The ST_AsText is important, I figured it out based on https://postgis.gishub.org/chapters/geometries.html#casting-from-text.

However, I'm not sure if SRID is preserved this way?

I know I could do: 'SRID=4326;' || ST_AsText(...).

@Maxxen
Copy link
Member

Maxxen commented Jan 17, 2025

Hello!
This is currently not supported, the DuckDB Postgres adapter has no knowledge of the spatial extension (or postgis). It's something Ive wanted to implement but I can't currently provide a timeline of when I will get to it.

INSERT INTO db.points (SELECT name, ST_AsText(ST_GeomAsHEXEWKB(pt)) AS pt FROM my_other_source);

This doesn't look right to me but if it work I guess it works? The way I'd go about it is to first convert to WKB on the DuckDB side (with ST_AsWKB(geom)::BLOB) and then convert back from WKB on the postgis side (ST_GeomFromWKB(blob))

However, I'm not sure if SRID is preserved this way?

DuckDB spatial does not store or track the SRID in geometries, so it doesn't matter either way, you need to set the SRID postgis-side regardless.

@fvankrieken
Copy link

fvankrieken commented Jan 29, 2025

Seems like this is fixed by this duckdb/duckdb-postgres#291 which was just merged

Parallel issue in postgres extension repo: duckdb/duckdb-postgres#264

@CGenie
Copy link
Author

CGenie commented Jan 29, 2025

Splendid, thank you!

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