postgres-nio icon indicating copy to clipboard operation
postgres-nio copied to clipboard

Multi-dimensional arrays

Open IgorRosocha opened this issue 5 years ago • 3 comments

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.

IgorRosocha avatar Feb 27 '19 10:02 IgorRosocha

I have the same error, have you found solution?

Cassini-17 avatar Jul 09 '19 12:07 Cassini-17

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 avatar Jul 22 '19 17:07 IgorRosocha

@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.

RamblinWreck77 avatar Dec 11 '19 19:12 RamblinWreck77