1

This query throws an error:

EncodingPreset.where('default = ?', false)

ActiveRecord::StatementInvalid: PG::Error: ERROR:  syntax error at or near "default"
LINE 1: ...coding_presets".* FROM "encoding_presets"  WHERE (default = ...
                                                             ^
: SELECT "encoding_presets".* FROM "encoding_presets"  WHERE (default = 'f')

but this works:

EncodingPreset.where(:default => false)

Why is the first query not working?

Versions:

ruby-1.9.3-p194
activerecord-3.2.11

2 Answers 2

7

That's because default is a keyword and has to be put in quotes for use in a query. This should work:

EncodingPreset.where('"default" = ?', false)
3

default is reserved keyword in postgreSQL that's why it throws error. Change the column name with some other name, then it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.