Skip to content

Commit

Permalink
PG: be more restrictive when deducing non-nullability of columns in S…
Browse files Browse the repository at this point in the history
…QL result layers (fixes #1734)
  • Loading branch information
rouault committed Jul 22, 2019
1 parent ade6de9 commit e9bc15d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gdal/ogr/ogrsf_frmts/pg/ogrpgresultlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ OGRPGResultLayer::OGRPGResultLayer( OGRPGDataSource *poDSIn,
}
}

if( !osRequest.empty() )
CPLString osQuery(pszRawQueryIn);
// Only a INNER JOIN can guarantee that the non-nullability of source columns
// will be valid for the result of the join.
if( !osRequest.empty() &&
osQuery.ifind("LEFT JOIN") == std::string::npos &&
osQuery.ifind("RIGHT JOIN") == std::string::npos &&
osQuery.ifind("OUTER JOIN") == std::string::npos )
{
osRequest = "SELECT attnum, attrelid FROM pg_attribute WHERE attnotnull = 't' AND (" + osRequest + ")";
PGresult* hResult = OGRPG_PQexec(poDS->GetPGConn(), osRequest );
Expand Down

0 comments on commit e9bc15d

Please sign in to comment.