[postgis-users] Bug in astext?

Luis Mota luis.mota at iscte.pt
Tue Dec 10 17:46:10 PST 2002


Hi David.

In fact it is a very simple function... I include it at the end... It 
simply gets a latitude and a longitude and is supposed to build a 
geometry string refering to a specific srid (20790) no matter what the 
original srid (gcsID) was. The whole lot of quotes is because I want to 
use the result inside another funcion, where I concatenate this result 
with another select-string which is, in turn, the argument of an execute 
command.

The problem is that, if I don't use substring, the second assignment to 
returnText does not concatenate the last quote...

See this simpler example, without quotes:

 select astext(geom)||'anything else' from location;
                  ?column?                 
--------------------------------------------
 POINT(111796.838719878 198640.438022229)

Where has the 'anything else' gone?

If I do the same thing with a plain text field, the result is as expected:
 select slqtchild||'anything else' from location;
             ?column?             
-----------------------------------
 GeodeticLocationanything else

See what I mean?

Bye, Luís

PS: The definition of the function in question:

CREATE OR REPLACE FUNCTION geom_from_geodlocation (FLOAT,FLOAT,INT,TEXT)
       RETURNS TEXT AS'
       DECLARE
    latitude ALIAS FOR $1;
    longitude ALIAS FOR $2;
    gcsID ALIAS FOR $3;
    gcsAuthor ALIAS FOR $4;
    returnText TEXT;
       BEGIN
        returnText := astext(transform(geomfromtext(''''''POINT(''||
                        longitude||'' ''||
                        latitude||'')'''''',gcsID),
                       20790));
    returnText := ''''''''||
           substring(returnText FROM 1 FOR length(returnText)-1)
           ||'''''''';
    RETURN returnText;
       END'
LANGUAGE 'plpgsql';
David Blasby wrote:

>Luis,
>
>I've never had any problem with astext().  I'm not sure what your function is
>doing - its has too many single quotes all over it.  Perhaps you could reduce
>it to a simple SELECT statement?
>
>What does an unterminated string look like?
>
>dave
>ps. the postgresql text type isnt null-terminated (but often people put null
>terminated strings in them).  Its very much like a pascal string, except the
>length is 4 bytes.
>
>
>_______________________________________________
>postgis-users mailing list
>postgis-users at postgis.refractions.net
>http://postgis.refractions.net/mailman/listinfo/postgis-users
>





More information about the postgis-users mailing list