Hello Hans,

as far as I know, it is an SQL rule, that all selected attributes that are not 
queried with an aggregate function have to be part of the group by clause. If 
you run that query, your database server will check the syntax and throw that 
error. I'm not sure if the SQL server realizes the 'functional dependency' in 
your query as assumed by you.

Cheers,
Michael

-----Ursprüngliche Nachricht-----
Von: Qgis-user <[email protected]> Im Auftrag von Hans 
Skov-Petersen via Qgis-user
Gesendet: Montag, 17. Oktober 2022 08:00
An: [email protected]
Betreff: [Qgis-user] Functional dependency seem not working in group


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

_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to