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 /common_gdal.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 'common_gdal.py')
| -rw-r--r-- | common_gdal.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/common_gdal.py b/common_gdal.py index b91f8c5..401e0a5 100644 --- a/common_gdal.py +++ b/common_gdal.py @@ -27,7 +27,7 @@ from typing import Any, Optional from osgeo import gdal, ogr, osr -from common import BadConfiguration +from common import BadConfiguration, escape_identifier, getEscapedTableNamePG # pylint: disable-next=redefined-builtin def gdalVersionMin(maj : int = 0, min : int = 0, rev : int = 0) -> bool: @@ -362,3 +362,12 @@ def parseTimeZone(tz : str) -> int: else: tzFlag += ogr.TZFLAG_UTC return tzFlag + +def getEscapedTableName(lyr : ogr.Layer, extract_schema_from_layer_name : bool = True) -> str: + """Return the layer name as an escaped identifier, suitable for injection into SQL queries. + For the PostgreSQL driver, an optional boolean (default: True) indicates whether the first + dot character is used as the separator between the schema and the table name.""" + layername = lyr.GetName() + if lyr.GetDataset().GetDriver().ShortName == 'PostgreSQL': + return getEscapedTableNamePG(layername, extract_schema_from_layer_name) + return escape_identifier(layername) |
