My wild guess (not having worked with libpq) is to help the planner out by explicitly casting parameters, e.g.:<div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">

<div>ST_Intersects(\"geocol\"::geometry, $1::geometry)</div></blockquote><div><br></div><div>-Mike</div><div><br><div class="gmail_quote">On 21 May 2010 02:14, 郭家成 <span dir="ltr"><<a href="mailto:iron1103@gmail.com">iron1103@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><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>_______________________________________________<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></div>