How to read PostgreSQL spatial types supplied as strings #348
-
In PostgreSQL I can simply do, e.g.,
but that fails in DuckDb, even when using point-2d instead. I was eventually able to wrangle it like so:
(location being the name of that column), i.e., converting the string into a struct first. This is for a point, though; doing the same thing for more complex types like (multi-)polygons would be quite convoluted, if possible at all. Is there a simpler way that I missed? Note: Reposted from the main duckdb repo because it is more appropriate for this one; the earlier one was closed by me. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I think the conventional way to do this for the GEOMETRY type is to use WKT syntax and a cast. E.g. This works for the columnar types |
Beta Was this translation helpful? Give feedback.
-
The problem is that they are available to me exactly in the string form mentioned at the beginning, e.g.,
|
Beta Was this translation helpful? Give feedback.
I think the conventional way to do this for the GEOMETRY type is to use WKT syntax and a cast. E.g.
SELECT 'POINT (1 2)'::GEOMETRY
This works for the columnar types
POINT_2D
etc too, but as they are based on DuckDB'sSTRUCT
andLIST
types you should also be able to use struct/list-literal syntax. E.g.SELECT {'x': 1, 'y': 2}::POINT_2D;
orSELECT [{'x': 1, 'y': 2}, {'x': 3, 'y': 4}]::LINESTRING_2D;