2011-07-10 159 views
6

我正在從MySQL到Postgres,我在創建索引時遇到了問題。postgres創建索引

CREATE INDEX pointsloc ON table USING gist(point_col);

這是響應我回去:

錯誤:數據類型的點具有接入方法「要點」 提示沒有缺省操作符:必須指定一個操作符的索引或定義一個默認的運營商級爲數據類型。

我已經看到我需要指定索引的操作符類,可以使用不同的類,具體取決於您希望在列上使用的操作符的類型。我希望使用@>或〜來查找點是否在多邊形內。

我該如何指定操作符類?幫助請必須是一件簡單的事情,但我很難過!

編輯

下面是我的打印屏幕試圖索引添加到分支表:

        Table "public.branch" 
     Column  |  Type  |      Modifiers      
------------------+------------------+----------------------------------------------------- 
id    | integer   | not null default nextval('branch_id_seq'::regclass) 
name    | character(120) | 
center_point_lat | double precision | 
center_point_lng | double precision | 
center_point  | point   | 
Indexes: 
    "branch_pkey" PRIMARY KEY, btree (id) 

paul=# create index pt_idx on branch using gist (center_point); 
ERROR: data type point has no default operator class for access method "gist" 
HINT: You must specify an operator class for the index or define a default operator class for the data type. 

回答

3

似乎是工作正常,當我嘗試:

test=# create table test (pt point); 
CREATE TABLE 
test=# create index pt_idx on test using gist (pt); 
CREATE INDEX 

您確定您的point_col實際上類型point?因爲,如果它是一個varchar,那麼如果沒有btree_gist contrib,確實會失敗 - 即便如此,它也不會很有用。

+0

編輯我的問題顯示打印屏幕和我試圖添加索引...請告訴我,我很愚蠢:) –

+0

它可能是您的Postgresql版本。 (我正在運行9.1-beta,它增加了主要索引,所以這可能是我沒有得到任何錯誤的原因。) –

+0

這可能是我在Centos 5.5系統上使用8.1.23。做一個yum更新顯示我不能更新到較新的postgres版本.... :(,關於它如何使用8.1.23完成的任何想法。我似乎無法找到任何信息添加運算符類創建索引或甚至哪些我需要做多邊形/點搜索lol –