<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18828">



<DIV><FONT size=2 face=Arial>Many thanks Paul!</FONT></DIV>
<BLOCKQUOTE style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
  <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV style="FONT: 10pt arial; BACKGROUND: #e4e4e4; font-color: black"><B>From:</B> 
  <a href="http://n2.nabble.com/user/SendEmail.jtp?type=node&node=3921452&i=0" target="_top" rel="nofollow">[hidden email]</a> </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <a href="http://n2.nabble.com/user/SendEmail.jtp?type=node&node=3921452&i=1" target="_top" rel="nofollow">[hidden email]</a> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Friday, October 30, 2009 3:44 
  PM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [mapserver-users] PostGIS 
  syntax error</DIV>
  <DIV><BR></DIV>The format of DATA is 'geocolumn from geosource', so your DATA 
  should be <BR><BR>DATA &nbsp; &nbsp; &nbsp; "wkb_geometry from (SELECT 
  DISTINCT <BR><BR>not <BR><BR>DATA &nbsp; &nbsp; &nbsp; 
  "wkb_geometry,county,state from (SELECT DISTINCT <BR><BR>don't worry, the SQL 
  driver will add calls for those other columns <BR>when they are needed. You 
  just need to make sure your subselect always <BR>includes all the columns you 
  want used by other mapserver subsystems <BR>(label columns for labels, 
  template columns for templates, etc, etc) <BR><BR>P. <BR><BR>On Fri, Oct 30, 
  2009 at 1:23 PM, Ted Spradley &lt;<A href="http://n2.nabble.com/user/SendEmail.jtp?type=node&amp;node=3921386&amp;i=0" rel="nofollow" target=_top>[hidden email]</A>&gt; wrote: 
  <DIV class=shrinkable-quote><div class='shrinkable-quote'><BR>&gt; <BR>&gt; Hi All, Happy Halloween <BR>&gt; 
  <BR>&gt; Scenario: I doing a 'mode=query' of a layer that takes the result of 
  the <BR>&gt; query <BR>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;in 
  the layer template and sends a subsequent 'mode=nquery' <BR>&gt; request to a 
  <BR>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;different layer in 
  the mapfile. &nbsp;The 'nqueried' layer template <BR>&gt; then does a <BR>&gt; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'mode=nquerymap' to map the 
  results. <BR>&gt; <BR>&gt; 
  ################################################################# <BR>&gt; I 
  am getting the following syntax error from the 'nqueried' layer DATA <BR>&gt; 
  object: <BR>&gt; <BR>&gt; msPostGISLayerWhichShapes(): Query error. Error 
  (ERROR: &nbsp;syntax error at or <BR>&gt; near "," <BR>&gt; LINE 1: 
  ....wkb_geometry ) = 0) as myquery where wkb_geometry,county,st... <BR>&gt; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^ <BR>&gt; ) executing 
  query: select <BR>&gt; 
  encode(AsBinary(force_collection(force_2d("wkb_geometry,county,state")),'NDR'),'base64') 
  <BR>&gt; as geom,"ogc_fid" from (SELECT DISTINCT a.ogc_fid, a.wkb_geometry, 
  <BR>&gt; a.county, a.state FROM countyp020 a, countyp020 b WHERE 
  b.county='Brown <BR>&gt; County' AND b.state='TX' AND a.wkb_geometry 
  &amp;&amp; <BR>&gt; b.wkb_geometry AND distance( a.wkb_geometry, 
  b.wkb_geometry ) = 0) as <BR>&gt; myquery where wkb_geometry,county,state 
  &amp;&amp; <BR>&gt; GeomFromText('POLYGON((-98.7789255453408 <BR>&gt; 
  31.1572855453408,-98.7789255453408 31.1572855453408,-98.7789255453408 <BR>&gt; 
  31.1572855453408,-98.7789255453408 31.1572855453408,-98.7789255453408 <BR>&gt; 
  31.1572855453408))',-1) <BR>&gt; <BR>&gt; 
  ################################################################# <BR>&gt; 
  <BR>&gt; ################################################################# 
  <BR>&gt; Template for the request being sent to the layer: <BR>&gt; <BR>&gt; 
  &lt;input name="img" type="image" <BR>&gt; 
  src="/cgi-bin/mapserv?map=[map]&amp;mode=nquery&amp;qlayer=usa_counties_adjacent&amp;imgxy=[center_x] 
  <BR>&gt; [center_y]&amp;county=[county]&amp;state=[state]&amp;imgext=[mapext]" 
  width="[mapwidth]" <BR>&gt; height="[mapheight]" <BR>&gt; <BR>&gt; 
  ################################################################# <BR>&gt; 
  <BR>&gt; ################################################################# 
  <BR>&gt; MapServer's rendering of the above template: <BR>&gt; <BR>&gt; 
  &lt;input name="img" type="image" <BR>&gt; 
  src="/cgi-bin/mapserv?map=/path/to/mapfiles/mapfile.map&amp;mode=nquery&amp;qlayer=usa_counties_adjacent&amp;imgxy=800.0 
  <BR>&gt; 400.0&amp;county=Brown County&amp;state=TX&amp;imgext=-103.782053 
  28.661976 -93.782052 <BR>&gt; 33.658849" width="1600" height="800" &gt; 
  <BR>&gt; <BR>&gt; 
  ################################################################# <BR>&gt; 
  <BR>&gt; ################################################################# 
  <BR>&gt; Layer generating the syntax error: <BR>&gt; <BR>&gt; &nbsp; 
  &nbsp;LAYER <BR>&gt; &nbsp; &nbsp; &nbsp; &nbsp;NAME &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp;usa_counties_adjacent <BR>&gt; &nbsp; &nbsp; &nbsp; 
  &nbsp;TYPE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;POLYGON <BR>&gt; &nbsp; 
  &nbsp; &nbsp; &nbsp;STATUS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OFF <BR>&gt; 
  &nbsp; &nbsp; &nbsp; &nbsp;DEBUG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; 3 <BR>&gt; &nbsp; &nbsp; &nbsp; &nbsp;TEMPLATE &nbsp; 
  &nbsp; &nbsp; &nbsp;"/path_to_templates/countyp020_adjacent_bodytemplate.html" 
  <BR>&gt; <BR>&gt; &nbsp; &nbsp; &nbsp; &nbsp;CONNECTIONTYPE POSTGIS <BR>&gt; 
  &nbsp; &nbsp; &nbsp; &nbsp;CONNECTION "dbname=project1 user=postgres 
  password=password host=localhost <BR>&gt; port=5432" <BR>&gt; &nbsp; &nbsp; 
  &nbsp; &nbsp;DATA &nbsp; &nbsp; &nbsp; "wkb_geometry,county,state from (SELECT 
  DISTINCT <BR>&gt; a.ogc_fid, a.wkb_geometry, a.county, a.state FROM countyp020 
  a, countyp020 b <BR>&gt; WHERE b.county='%county%' AND b.state='%state%' AND 
  a.wkb_geometry &amp;&amp; <BR>&gt; b.wkb_geometry AND distance( 
  a.wkb_geometry, b.wkb_geometry ) = 0) as <BR>&gt; myquery using unique ogc_fid 
  using srid=-1" <BR>&gt; <BR>&gt; &nbsp; &nbsp; &nbsp; &nbsp;PROJECTION 
  <BR>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp;"init=epsg:4326" <BR>&gt; &nbsp; &nbsp; &nbsp; &nbsp;END <BR>&gt; &nbsp; 
  END &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# &nbsp; &nbsp; &nbsp; Layer 
  usa_counties_adjacent <BR>&gt; <BR>&gt; 
  ################################################################# <BR>&gt; 
  <BR>&gt; I have tested the syntax from the console in pgsql and get the 
  expected <BR>&gt; return. <BR>&gt; <BR>&gt; 
  ################################################################# <BR>&gt; 
  pgsql: <BR>&gt; <BR>&gt; SELECT county, state FROM (SELECT DISTINCT a.ogc_fid, 
  a.county, a.state FROM <BR>&gt; countyp020 a, countyp020 b WHERE 
  b.county='Harris County' AND b.state='TX' <BR>&gt; AND a.wkb_geometry 
  &amp;&amp; b.wkb_geometry AND distance( a.wkb_geometry, <BR>&gt; 
  b.wkb_geometry ) = 0 ORDER BY a.county) as myfoo; <BR>&gt; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; county &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | state 
  <BR>&gt; ----------------------------------------------------+------- <BR>&gt; 
  &nbsp;Brazoria County &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| TX 
  <BR>&gt; &nbsp;Chambers County &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp;| TX <BR>&gt; &nbsp;Fort Bend County &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; | TX <BR>&gt; &nbsp;Galveston County &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; | TX <BR>&gt; &nbsp;Harris County &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp;| TX <BR>&gt; &nbsp;Liberty County &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; | TX <BR>&gt; &nbsp;Montgomery County &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| TX <BR>&gt; &nbsp;Waller County &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| TX <BR>&gt; (8 rows) 
  <BR>&gt; <BR>&gt; <BR>&gt; Any error glaring out at you from DATA statement? 
  <BR>&gt; <BR>&gt; Thanks, <BR>&gt; Ted S. <BR>&gt; -- <BR>&gt; View this 
  message in context: <A href="http://n2.nabble.com/PostGIS-syntax-error-tp3921276p3921276.html" rel="nofollow" target=_top>http://n2.nabble.com/PostGIS-syntax-error-tp3921276p3921276.html</A><BR>&gt; 
  Sent from the Mapserver - User mailing list archive at Nabble.com. <BR>&gt; 
  _______________________________________________ <BR>&gt; mapserver-users 
  mailing list <BR>&gt; <A href="http://n2.nabble.com/user/SendEmail.jtp?type=node&amp;node=3921386&amp;i=1" rel="nofollow" target=_top>[hidden email]</A> <BR>&gt; <A href="http://lists.osgeo.org/mailman/listinfo/mapserver-users" rel="nofollow" target=_top>http://lists.osgeo.org/mailman/listinfo/mapserver-users</A><BR>&gt; 
  </DIV>_______________________________________________ </div>mapserver-users 
  mailing list <BR><A href="http://n2.nabble.com/user/SendEmail.jtp?type=node&amp;node=3921386&amp;i=2" rel="nofollow" target=_top>[hidden email]</A> <BR><A href="http://lists.osgeo.org/mailman/listinfo/mapserver-users" rel="nofollow" target=_top>http://lists.osgeo.org/mailman/listinfo/mapserver-users</A><BR></BLOCKQUOTE>

<br><hr align="left" width="300">
View this message in context: <a href="http://n2.nabble.com/PostGIS-syntax-error-tp3921276p3921452.html">Re: [mapserver-users] PostGIS syntax error</a><br>
Sent from the <a href="http://n2.nabble.com/Mapserver-User-f1969211.html">Mapserver - User mailing list archive</a> at Nabble.com.<br>