[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 

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;
 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;
 GeodeticLocationanything else

See what I mean?

Bye, Luís

PS: The definition of the function in question:

    latitude ALIAS FOR $1;
    longitude ALIAS FOR $2;
    gcsID ALIAS FOR $3;
    gcsAuthor ALIAS FOR $4;
    returnText TEXT;
        returnText := astext(transform(geomfromtext(''''''POINT(''||
                        longitude||'' ''||
    returnText := ''''''''||
           substring(returnText FROM 1 FOR length(returnText)-1)
    RETURN returnText;
LANGUAGE 'plpgsql';
David Blasby wrote:

>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?
>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

More information about the postgis-users mailing list