diff options
| author | Guilhem Moulin <guilhem@fripost.org> | 2026-03-05 16:00:08 +0100 |
|---|---|---|
| committer | Guilhem Moulin <guilhem@fripost.org> | 2026-03-05 22:56:29 +0100 |
| commit | 4bb4d381f193f14260fc9f56679588d8e455dc93 (patch) | |
| tree | 5e695654382cda35e3f7bc4786f209ece80e72fb /import_source.py | |
| parent | 05ac5b52a224d6eddb23d748a9d8e3ee5571341b (diff) | |
Use PostgreSQL schemas to partition layers.
Rather than putting everything in the 'postgis' schema using ':' as
hierarchy separator.
When the destination dataset is not PostgreSQL, the layers names are
prefixed using '$SCHEMA.' instead of '$SCHEMA:'
Diffstat (limited to 'import_source.py')
| -rw-r--r-- | import_source.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/import_source.py b/import_source.py index c04390e..289bc4c 100644 --- a/import_source.py +++ b/import_source.py @@ -49,6 +49,7 @@ from common_gdal import ( gdalGetMetadataItem, formatTZFlag, getSpatialFilterFromGeometry, + getEscapedTableName, ) def openOutputDS(def_dict : dict[str, Any]) -> gdal.Dataset: @@ -393,11 +394,9 @@ def clearLayer(lyr : ogr.Layer) -> None: if n == 0: # nothing to clear, we're good return - layername_esc = escape_identifier(lyr.GetName()) ds = lyr.GetDataset() - drv = ds.GetDriver() - if drv.ShortName == 'PostgreSQL': + if ds.GetDriver().ShortName == 'PostgreSQL': # https://www.postgresql.org/docs/15/sql-truncate.html query = 'TRUNCATE TABLE {table} CONTINUE IDENTITY CASCADE' op = 'Truncating' @@ -405,8 +404,8 @@ def clearLayer(lyr : ogr.Layer) -> None: query = 'DELETE FROM {table}' op = 'Clearing' logging.info('%s table %s (former feature count: %s)', op, - layername_esc, str(n) if n >= 0 else 'unknown') - ds.ExecuteSQL(query.format(table=layername_esc)) + lyr.GetName(), str(n) if n >= 0 else 'unknown') + ds.ExecuteSQL(query.format(table=getEscapedTableName(lyr))) def extractArchive(path : Path, destdir : str, fmt : str|None = None, @@ -967,7 +966,7 @@ def updateLayerCache(lyr : ogr.Layer, cache : ogr.Layer, '\'\')) AS hash_geom') if len(fields) == 0: raise RuntimeError('Empty field list in SELECT') - query = 'SELECT ' + ','.join(fields) + ' FROM ' + escape_identifier(layername) + ' t' + query = 'SELECT ' + ','.join(fields) + ' FROM ' + getEscapedTableName(lyr) + ' t' sort_by = next(listFieldsOrderBy(defn, unique=True, nullable=False), None) if sort_by is not None: |
