Hi,<br><br>Hopefully this is trivial problem that someone can help me out with quickly.&nbsp; Am trying to use the BOX3D function within a stored procedure, using coordinate values passed in as parameters.&nbsp; The problem is I cannot figure out how to specify the box3d command using these parameters.&nbsp; I guess it has to do with variable expansion and the use of apostrophes, and I&#39;ve played around a lot with these, but cannot get things to work.&nbsp; The code is as follows:<br>
<br>CREATE FUNCTION add_spatiotemporal_row(original_document_id_in int, north_in real, <br>&nbsp;&nbsp;&nbsp; south_in real, west_in real, east_in real, start_time_in timestamp, <br>&nbsp;&nbsp;&nbsp; end_time_in timestamp) RETURNS void AS <br>$$<br>&nbsp;&nbsp;&nbsp; DECLARE<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; spatial_db_id integer := null;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; temporal_db_id integer := null;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bbox varchar := west_in || &#39; &#39; || south_in || &#39;, &#39; || east_in || &#39; &#39; || north_in;<br>&nbsp;&nbsp;&nbsp; BEGIN<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- This inserts a new row in the spatial data table, if required<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IF west_in is not null AND east_in is not null AND<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; north_in is not null AND south_in is not null THEN<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; INSERT INTO SPATIAL_DATA (spatial_data_id, geometry, create_date) VALUES <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (DEFAULT, <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; setsrid(&#39;BOX3D(west_in+&quot; &quot;+south_in+&quot;, &quot;+east_in+&quot; &quot;+north_in)&#39;::box3d,4326),<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; current_timestamp);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SELECT MAX(spatial_data_id) INTO spatial_db_id FROM SPATIAL_DATA;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; END IF;<br>...<br><br>- this produces the following error:<br><br>Error: database error &lt;class &#39;pg.DatabaseError&#39;&gt; error &#39;ERROR:&nbsp; BOX3D parser - couldnt parse.&nbsp; It should look like: BOX3D(xmin ymin zmin,xmax ymax zmax) or BOX3D(xmin ymin,xmax ymax)<br>
CONTEXT:&nbsp; SQL statement &quot;INSERT INTO SPATIAL_DATA (spatial_data_id, geometry, create_date) VALUES (DEFAULT, setsrid(&#39;BOX3D(west_in+&quot; &quot;+south_in+&quot;, &quot;+east_in+&quot; &quot;+north_in)&#39;::box3d,4326), current_timestamp)&quot;<br>
PL/pgSQL function &quot;add_spatiotemporal_row&quot; line 9 at SQL statement<br><br>- if I swap the quotes and apostrophes around I get:<br><br>Error: database error &lt;class &#39;pg.DatabaseError&#39;&gt; error &#39;ERROR:&nbsp; column &quot;BOX3D(west_in+&#39; &#39;+south_in+&#39;, &#39;+east_in+&#39; &#39;+north_in)&quot; does not exist<br>
LINE 1: ..., geometry, create_date) VALUES (DEFAULT, setsrid(&quot;BOX3D(wes...<br>&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;&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>QUERY:&nbsp; INSERT INTO SPATIAL_DATA (spatial_data_id, geometry, create_date) VALUES (DEFAULT, setsrid(&quot;BOX3D(west_in+&#39; &#39;+south_in+&#39;, &#39;+east_in+&#39; &#39;+north_in)&quot;::box3d,4326), current_timestamp)<br>
<br>- I get this error a lot if I try and reference the variables directly in the call to BOX3D.<br><br>Lastly, if I use the declared variable, bbox to create the box3d I get the following:<br><br>Error: database error &lt;class &#39;pg.DatabaseError&#39;&gt; error &#39;ERROR:&nbsp; BOX3D parser - couldnt parse.&nbsp; It should look like: BOX3D(xmin ymin zmin,xmax ymax zmax) or BOX3D(xmin ymin,xmax ymax)<br>
CONTEXT:&nbsp; SQL statement &quot;INSERT INTO SPATIAL_DATA (spatial_data_id, geometry, create_date) VALUES (DEFAULT, setsrid(&#39;BOX3D(bbox)&#39;::box3d,4326), current_timestamp)&quot;<br><br>If&nbsp; I could get the first and third example to expand out the passed in parameters then things would work - please could someone help me here - it&#39;s driving me crazy!<br>
<br>Thanks,<br><br>Calum.<br><br>