2012-07-24 52 views
1

我使用PostgreSQL的Rails和它完全適用於這樣的疑問:Postgres的查詢在Rails的:其中不

# Does hstore_column contain key? 

scoped_users = User.where('hstore_column ? :key', key: 'name_of_key') 

現在我的問題:我怎樣才能反轉這個查詢/我怎樣才能找到所有用戶這不要是否指定了特定的密鑰?

# I tried this query amongst others, but it does not work: 

scoped_users = User.where('hstore_column ? :key = FALSE', key: 'name_of_key') 

感謝您的幫助!

回答

2

嘗試:

where('NOT (hstore_column ? :key)', key: 'name_of_key') 
+0

它的工作原理!非常感謝你。 – Railsana 2012-07-24 15:19:59