Skip to content

How to read PostgreSQL spatial types supplied as strings #348

Answered by Maxxen
stenon-olivier asked this question in Q&A
Discussion options

You must be logged in to vote

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's STRUCT and LIST types you should also be able to use struct/list-literal syntax. E.g. SELECT {'x': 1, 'y': 2}::POINT_2D; or SELECT [{'x': 1, 'y': 2}, {'x': 3, 'y': 4}]::LINESTRING_2D;

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@Maxxen
Comment options

Answer selected by stenon-olivier
Comment options

You must be logged in to vote
2 replies
@Maxxen
Comment options

@stenon-olivier
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants