[postgis-users] pl/pgsql getting ST_X output as REAL

Mike Toews mwtoews at gmail.com
Wed Oct 6 00:27:53 PDT 2010


A RECORD type is simply a row from a generic table. It has brackets
around it because it is a tuple. It is only text so you can see it. In
your case, it is a 1-row 1-column record tuple. You can get to the
contents of the record like a column of a table, that is you use a "."
and the field name.

So in your code, use something like this:

FOR x_value IN SELECT ST_X(the_geom) FROM stations LOOP
  RAISE NOTICE '%', x_value.st_x;
END LOOP;

So here, "st_x" is the double precision member (aka REAL8) of the
1-column tuple record "x_value". If you want a different name, you can
specify AS something_else in the SELECT part. If you want the y-value
in there too, that's easy to do.

-Mike

On 5 October 2010 07:12, Jan Saalbach <fire at dubmosphere.de> wrote:
> Hi all,
> on my journey to learning PostgreSQL and PostGis I am now trying to write a
> function in pl/pgsql. In this little program I would like to determine the
> frequency of different x-values of POINT3D objects to get an idea about how
> many "rows" were digitized.
>
> Therefore I would like to use the following command:
>
> FOR x_value IN SELECT ST_X(points) FROM table LOOP
>
> The problem is that in the DECLARE-section x_value has to be set to type
> RECORD.
>
> x_value RECORD;
>
> In the course of the program I would like to work with REAL values for
> convenience. How do I go about casting the x_value RECORD, which seems to be
> some kind of string with brackets around the value, to a REAL object? Any
> ideas?
>
> Regards
> Jan
>
>
> _______________________________________________
> 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