[QGIS-trac] [Quantum GIS] #2911: Enable the query builder for view that don't have unique id

Quantum GIS qgis at qgis.org
Wed Jul 28 08:33:42 EDT 2010


#2911: Enable the query builder for view that don't have unique id
------------------------------------------------+---------------------------
   Reporter:  pinux                             |              Owner:  nobody       
       Type:  bug                               |             Status:  new          
   Priority:  major: does not work as expected  |          Milestone:  Version 1.6.0
  Component:  Data Provider                     |            Version:  Trunk        
   Keywords:  Postgis, Query Builder, View      |   Platform_version:               
   Platform:  Windows                           |           Must_fix:  No           
Status_info:  0                                 |  
------------------------------------------------+---------------------------
 I have 2 tables:
 CREATE TABLE polygon (
   gid int UNIQUE,
   name varchar(100) NOT NULL,
   ....
   PRIMARY KEY (gid)
 ) ;

 And,

 CREATE TABLE line(
   gid int UNIQUE,
   name varchar(100) NOT NULL,
   ....
   PRIMARY KEY (gid)
 ) ;

 And a View that makes buffers for the table line and groups the elements
 by their names:

   CREATE OR REPLACE VIEW line_buffer AS
   SELECT DISTINCT
   min(l.gid) as gid,
   l.name,
   st_union(st_buffer(l.the_geom, 100)) AS the_geom
   FROM line l
   GROUP BY l.name
   ORDER BY l.name;

 When I create a View to select the elements from the table polygon that
 are intersected by the elements in line_buffer, like this:

   CREATE OR REPLACE VIEW intersection AS
 SELECT DISTINCT
 p.*
    FROM
      polygon p,
      line l
    WHERE st_intersects(p.the_geom, ST_merge(l.the_geom)) = TRUE;

 When I insert more then 1 element with different names in the table line
 the result is a View without a column with unique value, because more than
 one element in line intersects the elements in polygon. If I try to add a
 query (Build query) in the Add Postgis tables window, qgis tell me that
 the view don't have a valid column with unique value. But if i write the
 query ("name"='test1') directly under Sql, I can open the view in qgis.
 So I suggest that if a view don't have a valid column with unique value it
 should be possible to open the Build query.

-- 
Ticket URL: <https://trac.osgeo.org/qgis/ticket/2911>
Quantum GIS <http://qgis.org>
Quantum GIS is an Open Source GIS viewer/editor supporting OGR, PostGIS, and GRASS formats


More information about the QGIS-trac mailing list