<p dir="ltr">Je ne pense pas être le destinataire de ce message </p>
<br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Le ven. 7 févr. 2025, 19:16, Regina Obe <<a href="mailto:lr@pcorp.us">lr@pcorp.us</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> Hello,<br>
> <br>
> Bellow my case and the steps to reproduce :<br>
> <br>
> /* About my database */<br>
> SELECT VERSION();<br>
> -- PostgreSQL 16.4, compiled by Visual C++ build 1941, 64-bit SELECT<br>
> POSTGIS_VERSION();<br>
> -- 3.4 USE_GEOS=1 USE_PROJ=1 USE_STATS=1<br>
> <br>
> /* Create a table with a generic geometry column with french CC48 3948<br>
SRID */<br>
> CREATE TEMP TABLE temp_geometry_tab (<br>
> id INTEGER NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,<br>
> geom GEOMETRY(GEOMETRY, 3948)<br>
> );<br>
> -- CREATE TABLE<br>
> -- Query returned successfully in 117 msec.<br>
> <br>
> /* Add two rows, one with a point geometry and another with multipolygon<br>
*/<br>
> INSERT INTO temp_geometry_tab (geom) VALUES ('POINT (2049346<br>
> 7276066)'), ('MULTIPOLYGON (((2049302 7274650,2050712<br>
> 7276342,2051981 7276013,2050865 7275954,2049795 7274791,2049948<br>
> 7274050,2049302 7274650)))') ;<br>
> -- INSERT 0 2<br>
> -- Query returned successfully in 71 msec.<br>
> <br>
> /* Create a view to filter the point geometries and cast them into points<br>
*/<br>
> CREATE TEMP VIEW temp_geometry_view AS SELECT<br>
> id,<br>
> geom::GEOMETRY(POINT, 3948)<br>
> FROM temp_geometry_tab<br>
> WHERE ST_GeometryType(geom) IN ('ST_Point') ;<br>
> -- CREATE VIEW<br>
> -- Query returned successfully in 83 msec.<br>
> <br>
> /* When I try to intersect the view geometry, an error occurs as if I<br>
query the<br>
> base table */ SELECT id FROM temp_geometry_view WHERE geom &&<br>
> ST_MakeEnvelope(2041534,7271489,2059551,7281479,3948)<br>
> ;<br>
> -- ERROR: Geometry type (MultiPolygon) does not match column type (Point)<br>
> -- SQL state: 22023<br>
> <br>
> /* When I try to query the first view with and additional filter it works<br>
*/ SELECT<br>
> id,<br>
> geom::GEOMETRY(POINT, 3948)<br>
> FROM temp_geometry_tab<br>
> WHERE<br>
> ST_GeometryType(geom) IN ('ST_Point')<br>
> AND geom &&<br>
> ST_MakeEnvelope(2041534,7271489,2059551,7281479,3948)<br>
> ;<br>
> -- id: 1 | geom:<br>
> 01010000206C0F00000000000042453F410000008088C15B41<br>
> <br>
> <br>
> Is-it normal that the filter consider the whole base table with<br>
multipolygon<br>
> geometries while only point type geometries are filtered in the queried<br>
view?<br>
> <br>
> Regards,<br>
> Julien Monticolo<br>
> <br>
I think in the past it might not have been possible but I don't think there<br>
is a guarantee that the WHERE clause always gets checked before the SELECT<br>
part is applied.<br>
<br>
I suppose you could get around it, not nice by doing this<br>
<br>
CREATE TEMP VIEW temp_geometry_view AS SELECT<br>
id,<br>
CASE WHEN ST_GeometryType(geom) IN ('ST_Point') THEN geom ELSE NULL<br>
END::GEOMETRY(POINT, 3948)<br>
FROM temp_geometry_tab<br>
WHERE ST_GeometryType(geom) IN ('ST_Point') ;<br>
<br>
I think adding in a pointless OFFSET also forces WHERE clause to be<br>
processed first, though that is a very oldish hack too<br>
<br>
CREATE TEMP VIEW temp_geometry_view AS SELECT<br>
id,<br>
geom::GEOMETRY(POINT, 3948)<br>
FROM temp_geometry_tab<br>
WHERE ST_GeometryType(geom) IN ('ST_Point')<br>
OFFSET 0;<br>
<br>
I think also using a CHECK option on the view might work though that<br>
designed to prevent updates that would prevent a record from being filtered<br>
out of the view by updating the condition that makes it a member and not for<br>
this situation:<br>
<br>
Something like<br>
<br>
<br>
CREATE TEMP VIEW temp_geometry_view AS SELECT<br>
id,<br>
geom::GEOMETRY(POINT, 3948)<br>
FROM temp_geometry_tab<br>
WHERE ST_GeometryType(geom) IN ('ST_Point')<br>
WITH CHECK OPTION ;<br>
<br>
<br>
<br>
</blockquote></div>