Hello,<br><br>Following what Kevin said about UNION ALL, I have tried to change the code (below) using UNION ALL and then SELECT DISTINCT (as I need the same X may be in both functions and I don't want a replicate. But I still ge the same error (eventual single-point Linestring that should never happen. Here is the code (so that I don't need to look-up the previous message:<br>
<br> ...header...<br>
SELECT st_LineFromMultiPoint(st_Collect(st_MakePoint(xy.t,<a href="http://xy.at/" target="_blank">xy.at</a>)))<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
FROM (SELECT q.t, dr_delay_value($1,q.t) + dr_delay_value($3,dr_delay_value($1,q.t)) AS at</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
--- dr_delay_value is a simple look-up function for a certain X value....<br>
FROM (SELECT st_X(st_PointN($1,n)) AS t<br>
FROM generate_series(1,st_NumPoints($1)) AS h(n)<br>
UNION<br>
SELECT st_X(st_PointN($2,n)) AS t<br>
FROM generate_series(1,st_NumPoints($2)) AS h(n)<br>
UNION<br>
SELECT st_Xmax($1) AS t<br>
) AS q ORDER BY q.t) AS xy<br>
...bottom...</blockquote><div><br>I then changed it to:<br> <br></div>
SELECT st_LineFromMultiPoint(st_Collect(st_MakePoint(xy.t,<a href="http://xy.at/" target="_blank">xy.at</a>)))<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
FROM (SELECT DISTINCT q.t, dr_delay_value($1,q.t) + dr_delay_value($3,dr_delay_value($1,q.t)) AS at</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
--- dr_delay_value is a simple look-up function for a certain X value....<br>
FROM (SELECT st_X(st_PointN($1,n)) AS t<br>
FROM generate_series(1,st_NumPoints($1)) AS h(n)<br>
UNION ALL<br>
SELECT st_X(st_PointN($2,n)) AS t<br>
FROM generate_series(1,st_NumPoints($2)) AS h(n)<br>
UNION<br>
SELECT st_Xmax($1) AS t<br>
) AS q ORDER BY q.t) AS xy<br>
...bottom...</blockquote><br>And I know what went inside when I got the error was:<br><br>Inputs of function:<br>$1 = LINESTRING(28800 28809.0366506299,28826.9908145614 28836.029580065) <br>$2 = LINESTRING(28800 45.4281818181818,28826.9908145614 45.4299607582325)<br>
$3 = LINESTRING(0 43.53,52800 47.01,62700 74.87,86400 43.53) - edge delay function<br><br>Output:<br>result =<br>LINESTRING(28800 28854.4654280455) - thus is missing a pair X=28826.9908145614, Y = 28836.029580065 + Y of $3 for 28836.029580065<br>
<br>But here is what I find most intriguing: if I simulate the inputs above outside of the main function (in which this one that is returning an eventual error runs), it simply works.<br><br>SELECT st_AsText(dr_sum_arrivaltime_edgedelay(st_GeometryFromText('LINESTRING(28800 28809.0366506299,28826.9908145614 28836.029580065)'), <br>
st_GeometryFromText('LINESTRING(28800 45.4281818181818,28826.9908145614 45.4299607582325)'),<br> st_GeometryFromText('LINESTRING(0 43.53,52800 47.01,62700 74.87,86400 43.53)')))<br>
<br>= "LINESTRING(28800 28854.4654280455,28826.9908145614 28881.46013656)"<br><br>I hope anyone can give me a clue on that one. It's sort of really bothering already, as I can't imagine why that happens...<br>
<br>Best regards,<br><br>Rodrigo Sperb<br><br><br><br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
------------------------------<br>
<br>
Message: 7<br>
Date: Sun, 08 Nov 2009 09:25:37 -0800<br>
From: Kevin Neufeld <<a href="mailto:kneufeld@refractions.net">kneufeld@refractions.net</a>><br>
Subject: Re: [postgis-users] Is that possible a function to behave<br>
differently inside and outside another main function code?<br>
To: PostGIS Users Discussion <<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a>><br>
Message-ID: <<a href="mailto:4AF6FF11.3080607@refractions.net">4AF6FF11.3080607@refractions.net</a>><br>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br>
<br>
Are you sure you want to use "UNION" and not "UNION ALL"? The former<br>
will remove duplicates, the latter does not. It's conceivable that when<br>
UNIONed, the three SELECT st_X clauses will return a single value.<br>
Collected and put through ST_LineFromMultiPoint would probably result in<br>
a single point line (depending on which version of PostGIS you are using<br>
- the newer versions will ERROR with "geometry requires more points").<br>
<br>
Hope that helps,<br>
Kevin<br>
<br>
rodrigosperb wrote:<br>
> Hello,<br>
><br>
> I have a bit of a problem that is sort of driving me crazy. I need to<br>
> perform an "addition of two (mathematical) functions". I represent them as<br>
> linestrings in my solution, and it is part of another bigger function. The<br>
> code is as follows:<br>
><br>
> ...header...<br>
> SELECT st_LineFromMultiPoint(st_Collect(st_MakePoint(xy.t,<a href="http://xy.at" target="_blank">xy.at</a>)))<br>
> FROM (SELECT q.t, dr_delay_value($1,q.t) +<br>
> dr_delay_value($3,dr_delay_value($1,q.t)) AS at<br>
> FROM (SELECT st_X(st_PointN($1,n)) AS t<br>
> FROM generate_series(1,st_NumPoints($1)) AS h(n)<br>
> UNION<br>
> SELECT st_X(st_PointN($2,n)) AS t<br>
> FROM generate_series(1,st_NumPoints($2)) AS h(n)<br>
> UNION<br>
> SELECT st_Xmax($1) AS t<br>
> ) AS q ORDER BY q.t) AS xy<br>
> ...bottom...<br>
> dr_delay_value() is simply a look-up function that takes the Y value for a<br>
> certain X.<br>
><br>
> The thing is that eventually this fuction is failing on returning more<br>
> specifically a 2-points linestring (that sould) and returns only a single<br>
> point one. Now, I have prepared a "wrapper" PL/Pgsql function to keep track<br>
> of what is passed to that function (perhaps that was the reason for the<br>
> error. With that I'm pretty much sure that the arguments passed are fine,<br>
> and still get the same error... Strangely, with my wrapper function keeping<br>
> track of the arguments passed to the function I was able to try out to run<br>
> the same request (that inside of the bigger function fails) separately, and<br>
> guess what? is simply works!!<br>
><br>
> I hope anyone may have a clue of what is going on. That's a very strange<br>
> behavior, I would say.<br>
><br>
> Regards,<br>
><br>
> Rodrigo Sperb<br>
><br>
<br>
<br>
------------------------------<br>
<br>
Message: 8<br>
Date: Sun, 8 Nov 2009 09:26:41 -0800 (PST)<br>
From: rodrigosperb <<a href="mailto:rodrigosperb@gmail.com">rodrigosperb@gmail.com</a>><br>
Subject: Re: [postgis-users] Is that possible a function to behave<br>
differently inside and outside another main function code?<br>
To: <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
Message-ID: <<a href="mailto:26255804.post@talk.nabble.com">26255804.post@talk.nabble.com</a>><br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
<br>
Hi Kevin,<br>
<br>
Thanks for your repply. I can't be sure whether the two functions have the<br>
same X value, and I don't want them twice, that's why I was using UNION,<br>
instead of UNION ALL (which is much faster even...).<br>
<br>
But what you said make some sense. Do you think if use first a UNION ALL and<br>
then in the outer query (when I order by q.t) I use DISTINCT may work?<br>
<br>
I think I will try it out.<br>
<br>
Thanks again for the help.<br>
<br>
Rodrigo Sperb<br>
<br>
<br>
<br>
Kevin Neufeld wrote:<br>
><br>
> Are you sure you want to use "UNION" and not "UNION ALL"? The former<br>
> will remove duplicates, the latter does not. It's conceivable that when<br>
> UNIONed, the three SELECT st_X clauses will return a single value.<br>
> Collected and put through ST_LineFromMultiPoint would probably result in<br>
> a single point line (depending on which version of PostGIS you are using<br>
> - the newer versions will ERROR with "geometry requires more points").<br>
><br>
> Hope that helps,<br>
> Kevin<br>
><br>
> rodrigosperb wrote:<br>
>> Hello,<br>
>><br>
>> I have a bit of a problem that is sort of driving me crazy. I need to<br>
>> perform an "addition of two (mathematical) functions". I represent them<br>
>> as<br>
>> linestrings in my solution, and it is part of another bigger function.<br>
>> The<br>
>> code is as follows:<br>
>><br>
>> ...header...<br>
>> SELECT st_LineFromMultiPoint(st_Collect(st_MakePoint(xy.t,<a href="http://xy.at" target="_blank">xy.at</a>)))<br>
>> FROM (SELECT q.t, dr_delay_value($1,q.t) +<br>
>> dr_delay_value($3,dr_delay_value($1,q.t)) AS at<br>
>> FROM (SELECT st_X(st_PointN($1,n)) AS t<br>
>> FROM generate_series(1,st_NumPoints($1)) AS h(n)<br>
>> UNION<br>
>> SELECT st_X(st_PointN($2,n)) AS t<br>
>> FROM generate_series(1,st_NumPoints($2)) AS h(n)<br>
>> UNION<br>
>> SELECT st_Xmax($1) AS t<br>
>> ) AS q ORDER BY q.t) AS xy<br>
>> ...bottom...<br>
>> dr_delay_value() is simply a look-up function that takes the Y value for<br>
>> a<br>
>> certain X.<br>
>><br>
>> The thing is that eventually this fuction is failing on returning more<br>
>> specifically a 2-points linestring (that sould) and returns only a single<br>
>> point one. Now, I have prepared a "wrapper" PL/Pgsql function to keep<br>
>> track<br>
>> of what is passed to that function (perhaps that was the reason for the<br>
>> error. With that I'm pretty much sure that the arguments passed are fine,<br>
>> and still get the same error... Strangely, with my wrapper function<br>
>> keeping<br>
>> track of the arguments passed to the function I was able to try out to<br>
>> run<br>
>> the same request (that inside of the bigger function fails) separately,<br>
>> and<br>
>> guess what? is simply works!!<br>
>><br>
>> I hope anyone may have a clue of what is going on. That's a very strange<br>
>> behavior, I would say.<br>
>><br>
>> Regards,<br>
>><br>
>> Rodrigo Sperb<br>
>><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>
><br>
<br>
--<br>
View this message in context: <a href="http://old.nabble.com/Is-that-possible-a-function-to-behave-differently-inside-and-outside-another-main-function-code--tp26251542p26255804.html" target="_blank">http://old.nabble.com/Is-that-possible-a-function-to-behave-differently-inside-and-outside-another-main-function-code--tp26251542p26255804.html</a><br>
Sent from the PostGIS - User mailing list archive at Nabble.com.<br>
<br>
<br>
<br>
------------------------------<br>
<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>
<br>
End of postgis-users Digest, Vol 87, Issue 9<br>
********************************************<br>
</blockquote></div><br>