postgres-nio
postgres-nio copied to clipboard
Multi-dimensional arrays
I have been trying to parse a GeoJSON, which has a multidimensional array coordinates
, example:
{
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
14.3894460970001,
49.951972148
],
[
14.3891214220001,
49.9524958600001
]
]
]
}
}
]
}
I'm having problem of saving multidimensional coordinates
of type [[[Double]]]
as a column into my database (which is described in my PosgtreSQLModel). In the DDL of created database, it has type jsonb[]
, and when I try to save it, I get PostgreSQLError.server.error.array_recv: wrong element type
. It would be really great if the support for multidimensional arrays would be available.
I have the same error, have you found solution?
I have the same error, have you found solution?
The only way that worked for me was to create a struct for geometry
in my model and then save the whole geometry
json as a database column, so the code looks like this:
/// A representation of Geometry
struct Geometry: Content {
/// Type of Geometry object
let type: String
/// Coordinates of Geometry object
let coordinates: [[[Double]]]
}
/// Geometry of Feature
var geometry: Geometry
@IgorRosocha This looks to be supported in the latest beta release. In my migrations I can do .array(of: .array(of .json)) and it seems to be working.