Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In a migration, a partial index is defined as follows to have only column price_1 where its value is greater than zero.

  add_index :products, :price_1, where: "(price_1 > '0')"

the schema states

  add_index "products", ["price_1"], :name => "index_products_on_price_1"

and the migration states

-- add_index(:products, :price_1, {:where=>"(price_1 > '0')"})

Neither rails nor postgreSQL seem to have complained.

However I am unsure as to whether the syntax is correct across the stack... and given this index is mission critical, I'm asking 'is air tight'?

exclude NULL values is also required. But I believe the definition covers that.

share|improve this question
    
Shouldn't "(price_1 > '0')" be "(price_1 > 0)"? You are comparing numbers rather than strings, aren't you? –  Uri Agassi Jun 18 at 10:40
    
Yes I'm comparing numbers. but 0 and 1 are also boolean values. Which raises my uncertainty –  Jerome Jun 18 at 10:43
    
but price_1 is a number... have you run any tests to see if it works as expected? –  Uri Agassi Jun 18 at 10:46
    
Forgot to mention that price_1 is a decimal. Getting expected results... I'll try your suggestion to see what happens. –  Jerome Jun 18 at 10:50
    
Returns the same expected results. –  Jerome Jun 18 at 11:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.