Skip to content

Commit a4b2e28

Browse files
committed
move function ID logic earlier
1 parent ae2880b commit a4b2e28

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

demo/initdb/02-functions.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ BEGIN
1919
dlat := (lat_max - lat_min) / num_y;
2020
RETURN QUERY
2121
SELECT
22-
x.x::text || '_' || y.y::text AS fid,
22+
x.x::text || '_' || y.y::text AS id,
2323
ST_MakeEnvelope(
2424
lon_min + (x.x - 1) * dlon, lat_min + (y.y - 1) * dlat,
2525
lon_min + x.x * dlon, lat_min + y.y * dlat, 4326
@@ -35,7 +35,7 @@ COMMENT ON FUNCTION postgisftw.us_grid IS 'Generates a grid of rectangles coveri
3535
CREATE OR REPLACE FUNCTION postgisftw.us_grid_noid(
3636
num_x integer DEFAULT 10,
3737
num_y integer DEFAULT 10)
38-
RETURNS TABLE(geom geometry)
38+
RETURNS TABLE(value text, geom geometry)
3939
AS $$
4040
DECLARE
4141
lon_min CONSTANT numeric := -128;
@@ -49,6 +49,7 @@ BEGIN
4949
dlat := (lat_max - lat_min) / num_y;
5050
RETURN QUERY
5151
SELECT
52+
x.x::text || '_' || y.y::text AS value,
5253
ST_MakeEnvelope(
5354
lon_min + (x.x - 1) * dlon, lat_min + (y.y - 1) * dlat,
5455
lon_min + x.x * dlon, lat_min + y.y * dlat, 4326

internal/data/catalog_db_fun.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ func scanFunctionDef(rows pgx.Rows) *Function {
115115

116116
geomCol := geometryColumn(outNames, datatypes)
117117

118+
idColumn := ""
119+
if conf.Configuration.Database.IdColumn != "" {
120+
if _, ok := datatypes[conf.Configuration.Database.IdColumn]; ok {
121+
idColumn = conf.Configuration.Database.IdColumn
122+
}
123+
}
124+
118125
funDef := Function{
119126
ID: id,
120127
Schema: schema,
@@ -130,6 +137,7 @@ func scanFunctionDef(rows pgx.Rows) *Function {
130137
OutJSONTypes: outJSONTypes,
131138
Types: datatypes,
132139
GeometryColumn: geomCol,
140+
IDColumn: idColumn,
133141
}
134142
//fmt.Printf("DEBUG: Function definitions: %v\n", funDef)
135143
return &funDef
@@ -190,7 +198,7 @@ func (cat *catalogDB) FunctionFeatures(ctx context.Context, name string, args ma
190198
return nil, errArg
191199
}
192200
propCols := removeNames(param.Columns, fn.GeometryColumn, "")
193-
idColIndex := indexOfName(propCols, conf.Configuration.Database.IdColumn)
201+
idColIndex := indexOfName(propCols, fn.IDColumn)
194202
sql, argValues := sqlGeomFunction(fn, args, propCols, param)
195203
log.Debugf("Function features query: %v", sql)
196204
log.Debugf("Function %v Args: %v", name, argValues)

internal/service/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ func writeFunItemsHTML(w http.ResponseWriter, name string, query string, urlBase
636636
context.Group = "Functions"
637637
context.Title = fn.ID
638638
context.Function = fn
639-
context.IDColumn = conf.Configuration.Database.IdColumn
639+
context.IDColumn = fn.IDColumn
640640

641641
// features are not needed for items page (page queries for them)
642642
return writeHTML(w, nil, context, ui.PageFunctionItems())

0 commit comments

Comments
 (0)