<div dir="ltr"><br><br>Hey dear lists,<div><br></div><div>Here is a self contained example showing strange behavior from a real life example concerning the use of postgis_topology topogeometry type.</div><div><br><br>The problem is :</div>
<div>when trying to return setof topogeometry,</div><div>the "return query" gives an error of type where there is none, and the return next is working fine.</div><div><br></div><div>The precise error message is ERROR 42804</div>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>"ERROR: structure of query does not match function result type</div><div><div>DETAIL: Returned type ttt.fake_topogeometry does not match expected type integer in column 1.</div>
</div><div><div>CONTEXT: PL/pgSQL function ttt.testtopogeom(ttt.fake_topogeometry) line 9 at RETURN QUERY</div></div><div><div>"</div></div></blockquote><div><br></div><div>Is it ok, postres bug, postgis bug?</div><div>
What are the possible corrections?</div><div><br></div><div><br><div><div>Here is the self contained code stored in the "ttt" schema.</div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div><div><div><br></div></div></div><div><div><div>DROP SCHEMA IF EXISTS ttt CASCADE;</div></div></div><div><div>CREATE SCHEMA ttt;</div></div><div><div><br></div></div><div><div>DROP TYPE IF EXISTS ttt.fake_topogeometry CASCADE;</div>
</div><div><div>CREATE TYPE ttt.fake_topogeometry AS</div></div><div><div> (topology_id integer,</div></div><div><div> layer_id integer,</div></div><div><div> id integer,</div></div><div><div> a_type integer);</div>
</div><div><div><br></div></div><div><div><span class="" style="white-space:pre"> </span>DROP FUNCTION IF EXISTS ttt.testTopogeom(test_topom ttt.fake_topogeometry);</div></div><div><div><span class="" style="white-space:pre"> </span>CREATE FUNCTION ttt.testTopogeom(test_topom ttt.fake_topogeometry)</div>
</div><div><div><span class="" style="white-space:pre"> </span>RETURNS SETOF ttt.fake_topogeometry AS</div></div><div><div><span class="" style="white-space:pre"> </span>$BODY$</div></div><div><div><span class="" style="white-space:pre"> </span>-- this function is an empty function to test return of multiple topogeom</div>
</div><div><div><span class="" style="white-space:pre"> </span>DECLARE</div></div><div><div><span class="" style="white-space:pre"> </span>the_topo ttt.fake_topogeometry;</div></div><div><div><span class="" style="white-space:pre"> </span>BEGIN</div>
</div><div><div><span class="" style="white-space:pre"> </span>RETURN NEXT (1,1,1,1)::ttt.fake_topogeometry;</div></div><div><div><span class="" style="white-space:pre"> </span>--RETURN NEXT (3,3,3,3)::ttt.fake_topogeometry;</div>
</div><div><div><br></div></div><div><div><span class="" style="white-space:pre"> </span>RETURN QUERY SELECT (1,1,1,1)::ttt.fake_topogeometry as foo;</div></div><div><div><span class="" style="white-space:pre"> </span>--<span class="" style="white-space:pre"> </span>UNION </div>
</div><div><div><span class="" style="white-space:pre"> </span>--SELECT (3,3,3,3)::ttt.fake_topogeometry as foo</div></div><div><div><span class="" style="white-space:pre"> </span>RETURN ;</div></div><div><div><span class="" style="white-space:pre"> </span>END ;</div>
</div><div><div><span class="" style="white-space:pre"> </span>$BODY$</div></div><div><div><span class="" style="white-space:pre"> </span>LANGUAGE plpgsql IMMUTABLE;</div></div><div><div><br></div></div><div><div><span class="" style="white-space:pre"> </span>SELECT *</div>
</div><div><div><span class="" style="white-space:pre"> </span>FROM ttt.testTopogeom((2,2,2,2)::ttt.fake_topogeometry);</div></div></blockquote><div><br></div></div>