Monday 10 July 2017

postgresql - ''More than one row returned by a subquery used as an expression'' postgres error


I am trying to realize a postgres request :



select distinct nom_reg_12 
from region_15,repartition
where st_intersects(region_15.geom,
(select geom
from repartition
where id_espece='Tetrarti'))=true;

but i get the following error :



More than one row returned by a subquery used as an expression




in the first time I tried this and it work fine :


select distinct nom_reg_12 
from region_15,repartition
where st_intersects(region_15.geom,repartition.geom)=true;

and then I tried this a part to get the geometry I want :


select geom from repartition where id_espece='Tetrarti'

Answer



you can move your condition outside of the subquery. ST_Intersects works on 1 row (for each geometry) at a time, so if you use a subquery it must also return just one row, and you probably have more than 1 'Tetrarti' row



select distinct nom_reg_12 
from region_15,repartition
where id_espece='Tetrarti'
and st_intersects(region_15.geom,
repartition.geom)=true;

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...