문제 설명
Postgres 쿼리에서 포인트 유형을 사용하는 방법 (Postgres how to use point type in query)
안녕하세요. Postgres SQL 테이블이 있습니다. 이 테이블의 한 열은 유형 포인트입니다.
CREATE TABLE public.geometry_cylinder
(
id serial not null primary key,
distance float not null,
height float not null,
coordinates point not null
);
SQL 쿼리에서 x 또는 y 좌표 중 하나를 사용하려면 어떻게 해야 합니까?
select * from public.geometry_cylinder where coordinates.x > 14.24
참조 솔루션
방법 1:
point
isn't a record type so you can't access x
and y
using the dot notation (though I admit, this would be logical). The explanation how to do it, is a bit hidden in the manual:
It is possible to access the two component numbers of a point as though the point were an array with indexes 0 and 1. For example, if t.p is a point column then SELECT p[0] FROM t retrieves the X coordinate
So you can use:
select *
from public.geometry_cylinder
where coordinates[0] > 14.24;
(by chatzich、a_horse_with_no_name)