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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ing(dot)Edmundo(dot)Robles(dot)Lopez" <erobles(at)sensacd(dot)com(dot)mx>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Getting X coordinate from a point(lseg), btw i read the man page about points.
Date: 2011-10-27 21:18:06
Message-ID: 6026.1319750286@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Ing.Edmundo.Robles.Lopez" <erobles(at)sensacd(dot)com(dot)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] = ... changes the 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Brian Fehrle 2011-10-27 21:22:33 Re: Server hitting 100% CPU usage, system comes to a crawl.
Previous Message Tom Lane 2011-10-27 20:50:36 Re: Server hitting 100% CPU usage, system comes to a crawl.