Re: [SQL] can I index a field of type "point"?

From: "Gene Selkov, Jr(dot)" <selkovjr(at)mcs(dot)anl(dot)gov>
To: pgsql-sql(at)postgreSQL(dot)org
Cc: mark(at)summersault(dot)com
Subject: Re: [SQL] can I index a field of type "point"?
Date: 2000-01-24 02:24:48
Message-ID: 200001240116.TAA26092@mail.xnet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> Hello!
>
>
> Is there a way to index a point field? The obvious method didn't work
> for me:
> mark=> create index lon_lat_idx on zip (lon_lat);
> ERROR: Can't find a default operator class for type 600

It is true that there is no default opclass for point. As a matter of
fact, there is no opclass for defined for point at all. You can try
box_ops, though:

create table zip (lon_lat point);
insert into zip values('120,47');
insert into zip values('120,48');
insert into zip values('120,49');
insert into zip values('122,47');
insert into zip values('124,60');

create index lon_lat_idx on zip using rtree (lon_lat box_ops);

This seems to work:

test=> select * from zip where lon_lat ~= '120,47';
lon_lat
--------
(120,47)
(1 row)

test=> select * from zip where lon_lat @ '120,45,125,49';
lon_lat
--------
(120,47)
(120,46)
(2 rows)

However, you might want to check it out with a substantial data set
and verify that this index is actually used. If it isn't, I would
simply represent points as boxes.

--Gene

Browse pgsql-sql by date

  From Date Subject
Next Message Mercury He 2000-01-24 04:11:19 Question about COPY command
Previous Message Mark Stosberg 2000-01-24 00:36:07 can I index a field of type "point"?