Обсуждение: Getting X coordinate from a point(lseg), btw i read the man page about points.
Getting X coordinate from a point(lseg), btw i read the man page about points.
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.
1st. i have a field
Column | Type | Modifiers
-----------+-----------------------+-------------------------------
id | integer | not null
info | lseg |
After read the above, i tried to
select info from table limit 1;
info
----------------------------------------------------
[(647753.125,2825633.75),(647738.8125,2825626.75)]
the value i want to get is: 647753.125
so i tried to do:
select info[0] from table limit 1;
info
-------------------------
(647753.125,2825633.75)
i still want to get 647753.125, so i did:
select info[0][0] from table limit 1;
info
------
(1 row)
But, nothing appears like a NULL.
then i did:
select point(info[0])[0] from table limit 1;
ERROR: syntax error at or near "["
LINE 1: select point(info[0])[0] from table limit 1;
and finally i wrote this mail :-)
Regards.
El contenido de este correo electrónico y sus archivos adjuntos son privados y confidenciales y va dirigido exclusivamente a su destinatario. No se autoriza la utilización, retransmisión, diseminación, o cualquier otro uso de esta información por un receptor o entidades distintas al destinatario. Si recibe este correo sin ser el destinatario se le solicita eliminarlo y hacerlo del conocimiento del emisor. La empresa no se hace responsable de transmisiones o comunicaciones no autorizadas o emitidas por personas ajenas a sus colaboradores utilizando éste medio electrónico.
The content of this email and its attached files are private and confidential and intended exclusively for the use of the individual or entity to which they are addressed. The retransmission, dissemination, or any other use of this information other than by the intended recipient is prohibited. If you have received this email in error please delete it and notify the sender. The company cannot be held liable for unauthorized electronic transmissions or communications, nor for those emitted by non-company individuals and entities.
"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