Many Thanks Mark !<br><br>Thought I had included parens grouping my where clause. Clearly I hadn't. Works brilliantly now.<br><br>Cheers,<br>dylan<br><br><div><span class="gmail_quote">On 4/11/07, <b class="gmail_sendername">
Mark Cave-Ayland</b> <<a href="mailto:mark.cave-ayland@ilande.co.uk">mark.cave-ayland@ilande.co.uk</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Tue, 2007-04-10 at 23:33 -0700, Dylan Lorimer wrote:<br>> Hi,<br>><br>> I'm curious if anyone can quickly see what I may be doing wrong here.<br>> I'm trying to restrict a query such that the geometry falls within a
<br>> specified BBOX. Basic PostGIS stuff....right?<br>><br>> However, for the following query, I'm not expecting to get any<br>> results, as the bbox specified has no points lying within it. And yet<br>> I get the result below.
<br>><br>> BOX3D is specified as (xmin ymin, xmax ymax) right?<br>><br>> So here's the query:<br>><br>>  SELECT AsText(the_geom) AS the_geom, FACILITY_N, OBJECTID,<br>> FACILITY_I, DEPTNAME FROM poi_2 WHERE lower(FACILITY_N) LIKE '%lafa%'
<br>> OR lower(OBJECTID) LIKE '%lafa%' OR lower(FACILITY_I) LIKE '%lafa%' OR<br>> lower(DEPTNAME) LIKE '%lafa%' AND the_geom && SetSRID('BOX3D(- 121.00<br>> 38.000, -119.00 40.00
)'::box3d,4326);<br>>         the_geom         |        facility_n        | objectid |<br>> facility_i |              deptname<br>> -------------------------+--------------------------+----------+------------+------------------------------------
<br>>  POINT(-122.497 37.7771) | LAFAYETTE SCHOOL (ELEM.) | 1969     |<br>> 0000003158 | SF Unified School District (SFUSD)<br>><br>> Here's the table description:<br>><br>> \d poi_2;<br>>            Table "
public.poi_2"<br>>    Column   |       Type        | Modifiers<br>> ------------+-------------------+-----------<br>>  facility_n | character varying |<br>>  objectid   | character varying |<br>>  facility_i | character varying |
<br>>  deptname   | character varying |<br>>  the_geom   | geometry          |<br>> Indexes:<br>>     "deptname_gepoi_2_idx" btree (lower(deptname::text))<br>>     "facility_i_gepoi_2_idx" btree (lower(facility_i::text))
<br>>     "facility_n_gepoi_2_idx" btree (lower(facility_n::text))<br>>     "objectid_gepoi_2_idx" btree (lower(objectid::text))<br>>     "the_geom_gepoi_2_idx" gist (the_geom)<br>> Check constraints:
<br>>     "enforce_dims_the_geom" CHECK (ndims(the_geom) = 2)<br>>     "enforce_geotype_the_geom" CHECK (geometrytype(the_geom) =<br>> 'POINT'::text OR the_geom IS NULL)<br>>     "enforce_srid_the_geom" CHECK (srid(the_geom) = 4326)
<br>><br>> Any ideas?<br>> Cheers,<br>> Dylan<br><br><br>Hi Dylan,<br><br>I think that what you're seeing here is a result of operator precedence<br>- see the table in the PostgreSQL documentation here:<br>
<a href="http://www.postgresql.org/docs/8.2/interactive/sql-syntax-lexical.html#SQL-PRECEDENCE">http://www.postgresql.org/docs/8.2/interactive/sql-syntax-lexical.html#SQL-PRECEDENCE</a>.<br><br>AFAICT your query is actually being parsed like this (brackets added for
<br>emphasis):<br><br><br>SELECT AsText(the_geom) AS the_geom, FACILITY_N, OBJECTID, FACILITY_I,<br>DEPTNAME FROM poi_2<br>WHERE lower(FACILITY_N) LIKE '%lafa%'<br>OR lower(OBJECTID) LIKE '%lafa%'<br>OR lower(FACILITY_I) LIKE '%lafa%'
<br>OR<br>  (lower(DEPTNAME) LIKE '%lafa%' AND the_geom && SetSRID('BOX3D(-121.00<br>38.000, -119.00 40.00)'::box3d,4326));<br><br><br>Hence your single row is being returned as a match on "lower(FACILITY_N)
<br>LIKE '%lafa%'". I think that what you are probably looking for is this<br>(again note the position of the extra brackets):<br><br><br>SELECT AsText(the_geom) AS the_geom, FACILITY_N, OBJECTID, FACILITY_I,
<br>DEPTNAME FROM poi_2<br>WHERE<br>  (lower(FACILITY_N) LIKE '%lafa%' OR lower(OBJECTID) LIKE '%lafa%' OR<br>  lower(FACILITY_I) LIKE '%lafa%' OR lower(DEPTNAME) LIKE '%lafa%')<br>AND<br>  the_geom && SetSRID('BOX3D(- 
121.00 38.000, -119.00<br>40.00)'::box3d,4326);<br><br><br>This should cause your row to match only if *any* of the fields contain<br>a reference to "lafa" AND the geometry lies within the specified<br>bounding box.
<br><br><br>Kind regards,<br><br>Mark.<br><br><br>_______________________________________________<br>postgis-users mailing list<br><a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net
</a><br><a href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br></blockquote></div><br><br clear="all"><br>-- <br>E. Dylan Lorimer | Google Earth Enterprise
<br>650.253.2459 (O) | 415.690.3347 (M) | 650.644.0182 (F)<br><br>This email and the information it contains are confidential and may be privileged. If you have received this email in error please notify me immediately and do not copy it for any purpose, or disclose its contents to any other person.  Internet communications are not secure and, therefore, Google does not accept legal responsibility for the contents of this message as it has been transmitted over a public network. If you suspect the message may have been intercepted or amended please call me.