How to store PostGIS Point with entgo / pgx?

205 views Asked by At

I'm having trouble saving a PostGIS point with entgo and pgx.

I try to use the pgtype.Point type from pgx, the schema looks like this:

// Fields of the Event.
func (EventSchema) Fields() []ent.Field {
    return []ent.Field{
        field.UUID("id", uuid.UUID{}).Immutable().
            Annotations(&entsql.Annotation{
                Default: "gen_random_uuid()"
            }),
        field.Other("location", &pgtype.Point{}).
            SchemaType(map[string]string{
                dialect.Postgres: "geometry(point, 4326)"
            }).StorageKey("location").Optional(),
    }
}

In the database, the type of "location" is also geometry(point, 4326).

The query to create: db.EventSchema.Create().SetLocation(point).Save()

leads to the error: ERROR: parse error - invalid geometry (SQLSTATE XX000)

Can't I just use pgtype.Point here, but do some formatting? Or does anyone have a working example with a different point type, e.g. with go-geom?

Thanks for your help!

0

There are 0 answers