<div>Hi Mike,</div>
<div>Thanks for your reply, but it still doesn't work.</div>
<div>The key point possibly lies in <strong>Oid paramtypes[1]={0}</strong>, </div>
<div>Where can I find the ParamType of Geometry or Bytea?</div>
<div> </div>
<div class="gmail_quote">2010/5/24 Mike Toews <span dir="ltr"><<a href="mailto:mwtoews@gmail.com">mwtoews@gmail.com</a>></span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">My wild guess (not having worked with libpq) is to help the planner out by explicitly casting parameters, e.g.: 
<div><br></div>
<blockquote style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 0px 40px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0px">

<div>ST_Intersects(\"geocol\"::geometry, $1::geometry)</div></blockquote>
<div><br></div>
<div>-Mike</div>
<div><br>
<div class="gmail_quote">
<div>
<div></div>
<div class="h5">On 21 May 2010 02:14, ³¢®a¦¨ <span dir="ltr"><<a href="mailto:iron1103@gmail.com" target="_blank">iron1103@gmail.com</a>></span> wrote:<br></div></div>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>
<div></div>
<div class="h5">
<div>Hi !</div>
<div>I try to create a view from a spatial table, but it can't be done successfully, please give me some hints.</div>
<div> </div>
<div>Here is how I create my spatial table:</div>
<div> </div>
<div><strong>CREATE TABLE "table_name" ("ID" SERIAL PRIMARY KEY);<br>SELECT ADDGEOMETRYCOLUMN('', 'table_name', 'geocol', -1, 'MULTIPOLYGON', 2);</strong></div>
<div> </div>
<div>After I inserted 1000 records into this table, I try to create a view with libpq:</div>
<div> </div>
<div><strong>int wkblen=0;</strong></div>
<div><strong>char *pwkb = MakeWKB(&wkblen);</strong> // I wrote a function to make wkb format, the function works fine.</div>
<div><strong>Oid paramtypes[1]={0};</strong></div>
<div><strong>char* paramvalues[1]={pwkb};</strong></div>
<div><strong>int paramlens[1]={wkblen};<br>int paramformats[1]={1};</strong></div>
<div><strong>int resultformat=1;</strong></div>
<div> </div>
<div><strong>PGresult *r = PQexecParams(conn,</strong></div>
<div><strong>              "CREATE VIEW \"view_name\" AS SELECT * FROM \"table_name\" WHERE ST_Intersects(\"geocol\", $1)",</strong></div>
<div><strong>              1,</strong></div>
<div><strong>              paramtypes,</strong></div>
<div><strong>              paramvalues,</strong></div>
<div><strong>              paramlens,</strong></div>
<div><strong>              paramformats,</strong></div>
<div><strong>              resultformat);</strong></div>
<div><strong>ExecStatusType est = PQresultstatus(r);</strong></div>
<div> </div>
<div>The ExecStatusType is always be <strong>PGRES_FATAL_ERROR</strong>, and Error Message is <strong>"could not determine data type of parameter $1"</strong>.</div>
<div>I have no idea what's going on, because when I change the SQL syntax to:</div>
<div> </div>
<div><strong>"SELECT * FROM \"table_name\" WHERE ST_Intersects(\"geocol\", $1)"</strong></div>
<div> </div>
<div>The ExecStatusType will be PGRES_TUPLES_OK.</div>
<div> </div>
<div>Please give me some hints, Thanks !</div>
<div> </div>
<div> </div>
<div> </div>
<div> </div><br></div></div>_______________________________________________<br>postgis-users mailing list 
<div class="im"><br><a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a><br></div>
<div class="im"><a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br><br></div></blockquote></div><br></div><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" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
<br></blockquote></div><br>