Skip to content
Permalink
Browse files

[DBManager] Use ST_EstimatedExtent with newer PostGIS

  • Loading branch information
github-actions authored and nyalldawson committed Mar 17, 2020
1 parent 35f6499 commit 694edc042417278ee47f4efcbde5167af7720694
Showing with 10 additions and 1 deletion.
  1. +10 −1 python/plugins/db_manager/db_plugins/postgis/connector.py
@@ -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

0 comments on commit 694edc0

Please sign in to comment.
You can’t perform that action at this time.