You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use pgx to insert and retrieve a gps point:
// Establish a connection to the databaseconn, err:= pgx.Connect(context.Background(), <CONNECTION_STRING>)
iferr!=nil {
log.Fatal(err)
}
// Ensure we have PostGIS on the database_, err=conn.Exec(context.Background(), "CREATE EXTENSION IF NOT EXISTS postgis")
iferr!=nil {
log.Fatal(err)
}
// Create the table with a PostGIS column_, err=conn.Exec(context.Background(), ` CREATE TABLE IF NOT EXISTS gps_points ( id SERIAL PRIMARY KEY, geom geometry(Point, 4326) ); `)
iferr!=nil {
log.Fatal(err)
}
// Construct the PointS structpoint:= pq_types.PostGISPoint{Lon: 37.6088900, Lat: 55.8219130}
// Insert the GPS point into the table_, err=conn.Exec(context.Background(), "INSERT INTO gps_points (geom) VALUES (ST_GeomFromText($1));", point)
iferr!=nil {
log.Fatal(err)
}
// Retrieve the GPS point from the databasevarretrievedPoint pq_types.PostGISPointerr=conn.QueryRow(context.Background(), "SELECT geom FROM gps_points WHERE id = $1;", 1).Scan(&retrievedPoint)
iferr!=nil {
log.Fatal(err)
}
fmt.Printf("Retrieved GPS point: %+v\n", retrievedPoint)
But I get back:
can't scan into dest[0]: PostGISPoint.Scan: expected []byte, got string (0101000020E6100000B98D06F0162055C0AF25E4839E8D4340)
The text was updated successfully, but these errors were encountered:
I'm trying to use pgx to insert and retrieve a gps point:
But I get back:
The text was updated successfully, but these errors were encountered: