Skip to content

Commit 03b3645

Browse files
committed
perform id fallback in go instead of sql
1 parent 2258c7f commit 03b3645

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

internal/data/catalog_db.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func tablesSorted(tableMap map[string]*Table) []*Table {
262262

263263
func (cat *catalogDB) readTables(db *pgxpool.Pool) map[string]*Table {
264264
log.Debugf("Load table catalog:\n%v", sqlTables)
265-
rows, err := db.Query(context.Background(), sqlTables, conf.Configuration.Database.IdColumn)
265+
rows, err := db.Query(context.Background(), sqlTables)
266266
if err != nil {
267267
log.Fatal(err)
268268
}
@@ -354,6 +354,13 @@ func scanTable(rows pgx.Rows) *Table {
354354
colDesc[i] = props.Elements[elmPos+2].String
355355
}
356356

357+
// default ID column if primary key not defined. check if conf.Configuration.Database.IdColumn is among columns
358+
if idColumn == "" && conf.Configuration.Database.IdColumn != "" {
359+
if _, ok := datatypes[conf.Configuration.Database.IdColumn]; ok {
360+
idColumn = conf.Configuration.Database.IdColumn
361+
}
362+
}
363+
357364
// Synthesize a title for now
358365
title := id
359366
// synthesize a description if none provided

internal/data/db_sql.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const sqlTables = `SELECT
3131
a.attname AS geometry_column,
3232
postgis_typmod_srid(a.atttypmod) AS srid,
3333
postgis_typmod_type(a.atttypmod) AS geometry_type,
34-
coalesce(ia.attname, fid.attname, '') AS id_column,
34+
coalesce(ia.attname, '') AS id_column,
3535
(
3636
SELECT array_agg(ARRAY[sa.attname, st.typname, coalesce(da.description,''), sa.attnum::text]::text[] ORDER BY sa.attnum)
3737
FROM pg_attribute sa
@@ -50,7 +50,6 @@ LEFT JOIN pg_description d ON (c.oid = d.objoid AND d.objsubid = 0)
5050
LEFT JOIN pg_index i ON (c.oid = i.indrelid AND i.indisprimary
5151
AND i.indnatts = 1)
5252
LEFT JOIN pg_attribute ia ON (ia.attrelid = i.indexrelid)
53-
LEFT JOIN pg_attribute fid ON (fid.attrelid = c.oid AND fid.attname = $1 AND fid.attnum > 0 AND NOT fid.attisdropped)
5453
LEFT JOIN pg_type it ON (ia.atttypid = it.oid AND it.typname in ('int2', 'int4', 'int8'))
5554
WHERE c.relkind IN ('r', 'v', 'm', 'p', 'f')
5655
AND t.typname IN ('geometry', 'geography')

0 commit comments

Comments
 (0)