From 480c93f01c3f9acfa56ee976483a5920e62f1bf3 Mon Sep 17 00:00:00 2001 From: Oliver Tonnhofer Date: Fri, 20 Jun 2014 10:09:28 +0200 Subject: [PATCH] support for custom geometry column names (e.g. way, the_geom) --- database/postgis/postgis.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/database/postgis/postgis.go b/database/postgis/postgis.go index 500703b..755c48f 100644 --- a/database/postgis/postgis.go +++ b/database/postgis/postgis.go @@ -56,12 +56,20 @@ func createTable(tx *sql.Tx, spec TableSpec) error { } func addGeometryColumn(tx *sql.Tx, tableName string, spec TableSpec) error { + colName := "geometry" + for _, col := range spec.Columns { + if col.Type.Name() == "GEOMETRY" { + colName = col.Name + break + } + } + geomType := strings.ToUpper(spec.GeometryType) if geomType == "POLYGON" { geomType = "GEOMETRY" // for multipolygon support } - sql := fmt.Sprintf("SELECT AddGeometryColumn('%s', '%s', 'geometry', '%d', '%s', 2);", - spec.Schema, tableName, spec.Srid, geomType) + sql := fmt.Sprintf("SELECT AddGeometryColumn('%s', '%s', '%s', '%d', '%s', 2);", + spec.Schema, tableName, colName, spec.Srid, geomType) row := tx.QueryRow(sql) var void interface{} err := row.Scan(&void)