2012-04-12 68 views
5

我一直在嘗試使用此命令檢索卡桑德拉數據庫中的數據後通過任何其他列:是否有可能在select語句的where子句卡桑德拉

select A_NO from Activity where CALL_TYPE IN ('MOC');//here CALL_TYPE is not the row id 

但其顯示:

Expected key 'KEY' to be present in where clause for 'Activity' 

cassandra是否可以在非主鍵的幫助下過濾數據?

回答

6

你不能直接在香草柱系列上做到這一點。 Cassandra默認只讓你查詢關鍵字或關鍵字範圍。您可以通過在列創建一個輔助指標完成這個

你會運行一個CQL這樣的查詢創建兩個指標:

cqlsh> CREATE INDEX state_key ON users (state); 
cqlsh> CREATE INDEX birth_year_key ON users (birth_year); 

然後詢問這樣的:

cqlsh> SELECT * FROM users 
... WHERE gender='f' AND 
... state='TX' AND 
... birth_year='1968'; 

Here is more on Secondary indexes.

Here is the documentation on using CQL for this.

+1

謝謝保羅。這真的很有幫助。非常感謝。 – abhi 2012-04-13 11:39:31

+1

確保您將答案標記爲已解決,以便其他人知道這是正確的。謝謝! – 2012-04-13 14:44:11