Open tconbeer opened 1 year ago
load spatial;
select st_point(0, 0) as pt
This will be hard, since duckdb casts it to binary when fetching an arrow table:
>>> cur = conn.sql("select st_point(0, 0) as pt")
>>> pat = cur.fetch_arrow_table()
>>> pat
pyarrow.Table
pt: binary
----
pt: [[0000180000000000000000000100000000000000000000000000000000000000]]
It's also binary when casting to python:
>>> cur.fetchall()
[(b'\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',)]
It does, however, tell you that it's a GEOMETRY type:
>>> cur.dtypes
[GEOMETRY]
The st_astext
spatial function exports well:
>>> cur = conn.sql("select st_astext(st_point(0, 0)) as pt")
>>> cur.fetch_arrow_table()
pyarrow.Table
pt: string
----
pt: [["POINT (0 0)"]]
So this would work:
>>> cur = conn.sql("select st_point(0, 0) as pt")
>>> rewritten = cur.project("st_astext(pt)")
>>> rewritten.fetch_arrow_table()
pyarrow.Table
st_astext(pt): string
----
st_astext(pt): [["POINT (0 0)"]]
(We would NOT want to do this rewriting when exporting the data, only when loading the table; we would also need to maintain the types)
e.g., POINT from spatial renders as binary instead of something like
POINT (-117.93367 34.34613)