<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>The "join" in your select makes it possible that the the primary
key urban.id won't be unique in the result set. You have to
either <br>
</p>
<ul>
<li>Put the column geom in a agregating function (ex. min(), max()
)<br>
</li>
<li>Or put column geom into your group by clause <br>
</li>
</ul>
<pre class="moz-signature" cols="72">Med venlig hilsen / Best regards
Bo Victor Thomsen</pre>
<div class="moz-cite-prefix">Den 17-10-2022 kl. 09:37 skrev Reetz,
Michael (NLPV) via Qgis-user:<br>
</div>
<blockquote type="cite"
cite="mid:91ac73ac218b44d0b07b8eea856dcc1f@nlpvw.niedersachsen.de">
<pre class="moz-quote-pre" wrap="">Hello Hans,
I didn't know that you are working with PostgreSQL. Since I don't work with PostgreSQL, I'm not familiar with the implementation of functional dependencies there. Maybe the problem is that you are using subselects or that geom is part of both tables. But this is just a guess, not knowledge.
Cheers,
Michael
-----Ursprüngliche Nachricht-----
Von: Hans Skov-Petersen <a class="moz-txt-link-rfc2396E" href="mailto:hsp@ign.ku.dk"><hsp@ign.ku.dk></a>
Gesendet: Montag, 17. Oktober 2022 09:05
An: Reetz, Michael (NLPV) <a class="moz-txt-link-rfc2396E" href="mailto:Michael.Reetz@nlpvw.niedersachsen.de"><Michael.Reetz@nlpvw.niedersachsen.de></a>
Cc: <a class="moz-txt-link-abbreviated" href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a>
Betreff: RE: Functional dependency seem not working in group
Dear Michael
Functional dependencies are, according the Net, applied in PostgreSQL: <a class="moz-txt-link-freetext" href="https://stackoverflow.com/questions/66065987/postgres-sql-column-must-appear-in-the-group-by-clause-or-be-used-in-an-aggrega">https://stackoverflow.com/questions/66065987/postgres-sql-column-must-appear-in-the-group-by-clause-or-be-used-in-an-aggrega</a>
And accordingly, you shouldn't worry about it in PostGIS. The funny thing is that sometime it works. Sometimes it doesn't.
Cheers
Hans
-----Original Message-----
From: Qgis-user <a class="moz-txt-link-rfc2396E" href="mailto:qgis-user-bounces@lists.osgeo.org"><qgis-user-bounces@lists.osgeo.org></a> On Behalf Of Reetz, Michael (NLPV) via Qgis-user
Sent: 17. oktober 2022 08:47
To: <a class="moz-txt-link-abbreviated" href="mailto:qgis-user@lists.osgeo.org">qgis-user@lists.osgeo.org</a>
Subject: Re: [Qgis-user] Functional dependency seem not working in group
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 <a class="moz-txt-link-rfc2396E" href="mailto:qgis-user-bounces@lists.osgeo.org"><qgis-user-bounces@lists.osgeo.org></a> Im Auftrag von Hans Skov-Petersen via Qgis-user
Gesendet: Montag, 17. Oktober 2022 08:00
An: <a class="moz-txt-link-abbreviated" href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a>
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
<a class="moz-txt-link-abbreviated" href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-user&data=05%7C01%7Chsp%40ign.ku.dk%7C1eb7efbdf32e4c3e425908dab00c602f%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C638015864588678289%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=outXdPjG2JC0yvxdhzHRhHRtLv%2FOsq9%2B6%2FaxU4df1%2Bk%3D&reserved=0">https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-user&data=05%7C01%7Chsp%40ign.ku.dk%7C1eb7efbdf32e4c3e425908dab00c602f%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C638015864588678289%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=outXdPjG2JC0yvxdhzHRhHRtLv%2FOsq9%2B6%2FaxU4df1%2Bk%3D&reserved=0</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-user&data=05%7C01%7Chsp%40ign.ku.dk%7C1eb7efbdf32e4c3e425908dab00c602f%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C638015864588678289%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=outXdPjG2JC0yvxdhzHRhHRtLv%2FOsq9%2B6%2FaxU4df1%2Bk%3D&reserved=0">https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-user&data=05%7C01%7Chsp%40ign.ku.dk%7C1eb7efbdf32e4c3e425908dab00c602f%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C638015864588678289%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=outXdPjG2JC0yvxdhzHRhHRtLv%2FOsq9%2B6%2FaxU4df1%2Bk%3D&reserved=0</a>
_______________________________________________
Qgis-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-user&data=05%7C01%7Chsp%40ign.ku.dk%7C1eb7efbdf32e4c3e425908dab00c602f%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C638015864588678289%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=outXdPjG2JC0yvxdhzHRhHRtLv%2FOsq9%2B6%2FaxU4df1%2Bk%3D&reserved=0">https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-user&data=05%7C01%7Chsp%40ign.ku.dk%7C1eb7efbdf32e4c3e425908dab00c602f%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C638015864588678289%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=outXdPjG2JC0yvxdhzHRhHRtLv%2FOsq9%2B6%2FaxU4df1%2Bk%3D&reserved=0</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-user&data=05%7C01%7Chsp%40ign.ku.dk%7C1eb7efbdf32e4c3e425908dab00c602f%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C638015864588678289%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=outXdPjG2JC0yvxdhzHRhHRtLv%2FOsq9%2B6%2FaxU4df1%2Bk%3D&reserved=0">https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-user&data=05%7C01%7Chsp%40ign.ku.dk%7C1eb7efbdf32e4c3e425908dab00c602f%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C638015864588678289%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=outXdPjG2JC0yvxdhzHRhHRtLv%2FOsq9%2B6%2FaxU4df1%2Bk%3D&reserved=0</a>
_______________________________________________
Qgis-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
</pre>
</blockquote>
</body>
</html>