3

Hello I have an Postgres SQL table, one column of its is type point

CREATE TABLE public.geometry_cylinder
(
    id          serial not null primary key,
    distance    float not null,
    height      float not null,
    coordinates point not null

);

how can I use one of x or y coordinates in an SQL query?

select * from public.geometry_cylinder where coordinates.x > 14.24

1 Answer 1

5

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.