Skip to content
Permalink
Browse files

postgres provider: allow detection of empty views (fixes #13638)

  • Loading branch information
jef-n committed Oct 20, 2015
1 parent b20d316 commit 441f6f8cf1c5a500c3e898bfbcdff6757e6d8d73
Showing with 3 additions and 6 deletions.
  1. +2 −5 src/providers/postgres/qgspostgresconn.cpp
  2. +1 −1 src/providers/postgres/qgspostgresprovider.cpp
@@ -588,9 +588,6 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
// catalog doesn't exist in postgresql so we ignore that, but we
// do need to get the geometry type.

// Make the assumption that the geometry type for the first
// row is the same as for all other rows.

QString tableName = result.PQgetvalue( i, 0 ); // relname
QString schemaName = result.PQgetvalue( i, 1 ); // nspname
QString column = result.PQgetvalue( i, 2 ); // attname
@@ -601,8 +598,8 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP

//QgsDebugMsg( QString( "%1.%2.%3: %4" ).arg( schemaName ).arg( tableName ).arg( column ).arg( relkind ) );

layerProperty.types.clear();
layerProperty.srids.clear();
layerProperty.types = QList<QGis::WkbType>() << QGis::WKBUnknown;
layerProperty.srids = QList<int>() << INT_MIN;
layerProperty.schemaName = schemaName;
layerProperty.tableName = tableName;
layerProperty.geometryColName = column;
@@ -1318,7 +1318,7 @@ bool QgsPostgresProvider::uniqueData( QString query, QString quotedColNames )
{
Q_UNUSED( query );
// Check to see if the given columns contain unique data
QString sql = QString( "SELECT count(distinct (%1))=count((%1)) AND bool_and((%1) IS NOT NULL) FROM %2%3" )
QString sql = QString( "SELECT count(distinct (%1))=count((%1)) FROM %2%3" )
.arg( quotedColNames,
mQuery,
filterWhereClause() );

3 comments on commit 441f6f8

@SebDieBln

This comment has been minimized.

Copy link
Contributor

@SebDieBln SebDieBln replied Oct 20, 2015

@jef-n Your change now not only allows empty queries/views but it also allows parts of the key to be NULL. Is this intended?
If not, I would suggest simply adding the clause IS NOT FALSE to the bool_and() function to avoid the problematic NULL result for this special case.

The following query does the same check as the one before except it returns true for an empty relation:

SELECT
   count(distinct (%1)) = count((%1))
   AND
   bool_and((%1) IS NOT NULL) IS NOT FALSE
FROM %2%3
@jef-n

This comment has been minimized.

Copy link
Member Author

@jef-n jef-n replied Oct 20, 2015

What's the problem with keys being partly NULL in the first place?

@SebDieBln

This comment has been minimized.

Copy link
Contributor

@SebDieBln SebDieBln replied Oct 20, 2015

The usual comparison semantics don't apply to NULL values. E.g. "Attribute" = NULL never yields TRUE, even if the attribute is NULL. It always yields NULL.

So at least here would be a problem. Maybe somewhere else, too.

See also my newly filed bug 13641.

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