Thread

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

    selkovjr@mcs.anl.gov — 2000-01-24T02:24:48Z

    > 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