Re: Getting X coordinate from a point(lseg), btw i read the man page about points. - Mailing list pgsql-general

From Tom Lane
Subject Re: Getting X coordinate from a point(lseg), btw i read the man page about points.
Date
Msg-id 6026.1319750286@sss.pgh.pa.us
Whole thread Raw
In response to Getting X coordinate from a point(lseg), btw i read the man page about points.  ("Ing.Edmundo.Robles.Lopez" <erobles@sensacd.com.mx>)
List pgsql-general
"Ing.Edmundo.Robles.Lopez" <erobles@sensacd.com.mx> writes:
> Hi in the main page about geometric operations said:
> It is possible to access the two component numbers of a  point  as though it were an array with indices 0 and 1. For
example,if  t.p  is a  point  column then  SELECT p[0] FROM t  retrieves the X coordinate and  UPDATE t SET p[1] = ...
changesthe Y coordinate. In the same way, a value of type  box  or  lseg  can be treated as an array of two  point
values.

> [ So how to get p2.x from an lseg value? ]

>   select  info[0] from table limit 1;
>   (647753.125,2825633.75)

Right, that gets you a point.

>   i still want to get647753.125, so i did:
> select  info[0][0] from table limit 1;

Close, but that notation only works for a 2-dimensional array, which an
lseg is not.  What you need is

regression=# select (info[0])[0] from table;
     f1
------------
 647753.125
(1 row)

The parenthesized object is a point, and then an entirely separate
subscripting operation has to be applied to it to get its X coordinate.

> then i did:
>   select point(info[0])[0]  from table limit 1;

Well, that's unnecessary since info[0] is already a point, but the
syntactic problem is again that you have to parenthesize the thing that
the second subscript is being applied to:

    select (point(info[0]))[0]  from table limit 1;

You need parentheses any time you're going to apply subscripting or
field selection to something that isn't a simple variable reference.

            regards, tom lane

pgsql-general by date:

Previous
From: Brian Fehrle
Date:
Subject: Re: Server hitting 100% CPU usage, system comes to a crawl.
Next
From: Tom Lane
Date:
Subject: Re: Server hitting 100% CPU usage, system comes to a crawl.