Description
Describe the bug
I have a project that uses Postgis to handle geospatial data. The issue is that columns using any Postgis types are generated with the postgres.ColumnString
type. So when I try to make an insert with the following code the result is wrapped with a string, so postgres never executes the postgis functions.
longitude := -80.292191
latitude := 42.841367
qb := table.Address.
INSERT(table.Address.Coordinates).
MODEL(model.Address{
Coordinates: fmt.Sprintf(
"ST_SetSRID(ST_MakePoint(%f, %f), 4326)",
longitude,
latitude,
)
})
The code above returns this output when use the debugger function:
INSERT INTO public.address (coordinates)
VALUES ('ST_SetSRID(ST_MakePoint(-80.292191, 42.841367), 4326)')
In the output the value is surrounded by single quotes, so postgres treats it as text
instead of geography(POINT, 4326)
.
Is there any way I could handle this case?
Environment:
- OS: linux
- Database: postgres
- Database driver: pq
- Jet version: 2.11.0
Code snippet
Here's the minimal SQL schema to get this to work. this does assume Postgis is installed (see installation instructions here)
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE TABLE "address" (
"id" BIGSERIAL UNIQUE PRIMARY KEY,
"coordinates" geography(POINT, 4326) NOT NULL
);
Expected behavior
The insert should return without surrounding the value for column coordinate
with single quotes. Like so:
INSERT INTO public.address (coordinates)
VALUES (ST_SetSRID(ST_MakePoint(-80.292191, 42.841367), 4326))