Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[DBManager] Use ST_EstimatedExtent with newer PostGIS
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Mar 17, 2020
1 parent 35f6499 commit 694edc0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion python/plugins/db_manager/db_plugins/postgis/connector.py
Expand Up @@ -732,7 +732,16 @@ def getTableEstimatedExtent(self, table, geom):
schema, tablename = self.getSchemaTableName(table)
schema_part = u"%s," % self.quoteString(schema) if schema is not None else ""

subquery = u"SELECT st_estimated_extent(%s%s,%s) AS extent" % (
pgis_versions = self.getSpatialInfo()[0].split('.')
pgis_major_version = int(pgis_versions[0])
pgis_minor_version = int(pgis_versions[1])
pgis_old = False
if pgis_major_version < 2:
pgis_old = True
elif pgis_major_version == 2 and pgis_minor_version < 1:
pgis_old = True
subquery = u"SELECT %s(%s%s,%s) AS extent" % (
'st_estimated_extent' if pgis_old else 'st_estimatedextent',
schema_part, self.quoteString(tablename), self.quoteString(geom))
sql = u"""SELECT st_xmin(extent), st_ymin(extent), st_xmax(extent), st_ymax(extent) FROM (%s) AS subquery """ % subquery

Expand Down

0 comments on commit 694edc0

Please sign in to comment.