Skip to content

Commit

Permalink
postgres provider: fix handling of queries in QgsPostgresConn::retrie…
Browse files Browse the repository at this point in the history
…veLayerTypes

(cherry picked from commit 93fe5b0)
  • Loading branch information
jef-n committed Jun 24, 2021
1 parent f219050 commit 66f0b69
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -1889,7 +1889,7 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l
else
{
// Query
table = quotedIdentifier( layerProperty.tableName );
table = QStringLiteral( "%1 AS t" ).arg( layerProperty.tableName );
}

if ( layerProperty.geometryColName.isEmpty() )
Expand All @@ -1912,7 +1912,7 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l
if ( useEstimatedMetadata )
{
sql = QStringLiteral( "SELECT %1, "
"array_agg( srid || ':RASTER:-1') "
"array_agg(srid || ':RASTER:-1') "
"FROM raster_columns "
"WHERE r_raster_column = %2 AND r_table_schema = %3 AND r_table_name = %4" )
.arg( i - 1 )
Expand All @@ -1923,10 +1923,10 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l
else
{
sql = QStringLiteral( "SELECT %1, "
"array_agg( DISTINCT ST_SRID( %2 ) || ':RASTER:-1' ) "
"array_agg(DISTINCT st_srid(%2) || ':RASTER:-1') "
"FROM %3 "
"%2 IS NOT NULL "
"%4 " // SQL clause
"%4" // SQL clause
"%5" )
.arg( i - 1 )
.arg( quotedIdentifier( layerProperty.geometryColName ) )
Expand All @@ -1944,7 +1944,7 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l
// our estimation ignores that a where clause might restrict the feature type or srid
if ( useEstimatedMetadata )
{
table = QStringLiteral( "(SELECT %1 FROM %2 WHERE %3%1 IS NOT NULL %4) AS t" )
table = QStringLiteral( "(SELECT %1 FROM %2 WHERE %3%1 IS NOT NULL%4) AS t" )
.arg( quotedIdentifier( layerProperty.geometryColName ),
table,
layerProperty.sql.isEmpty() ? QString() : QStringLiteral( " (%1) AND " ).arg( layerProperty.sql ) )
Expand Down Expand Up @@ -2002,7 +2002,7 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l
if ( type == QgsWkbTypes::Unknown )
{
// Subselect to limit the "array_agg(DISTINCT", see previous comment.
sql += QStringLiteral( " FROM (SELECT %1 from %2 %3) as _unused" )
sql += QStringLiteral( " FROM (SELECT %1 FROM %2%3) AS _unused" )
.arg( quotedIdentifier( layerProperty.geometryColName ) )
.arg( table )
.arg( tableScanLimit );
Expand Down

0 comments on commit 66f0b69

Please sign in to comment.