[Qgis-user] Functional dependency seem not working in group

Hans Skov-Petersen hsp at ign.ku.dk
Sun Oct 16 23:00:01 PDT 2022


Dear Friends

I have, what appears to be a classic problem: When running a selection including a group statement I get the good old 'ERROR:  column "urban.geom" must appear in the GROUP BY clause or be used in an aggregate function'.

I thought 'functional dependency' was in place to take care of that. The way I understand it, is that functional dependency will, as applied in e.g. the group statement, realize that e.g. the geom field is uniquely related to the id field (which is referred in the group statement). Am I right in my assumption?

This is the ode causing the trouble:

drop table if exists stevns_test_urban_ped;
create table stevns_test_urban_ped as 
  select urban.id as id, urban.geom as geom, min(urban.pop2019) as pop2019, count(forest) as ped, min(urban.pop2019)/(count(forest)+1)::float as pop_forest_ped 
  from (select * from stevns_test_p where lu_type = 1) as urban
  join (select * from stevns_test_p where lu_type = 2) as forest on ST_Distance(urban.geom, forest.geom) < 1000 and forest.geom && (ST_Expand(urban.geom, 1000))
  group by urban.id 
;

Never mind the logics or meaning :-)

Thanks
Cheers
Hans



More information about the Qgis-user mailing list