In ActiveRecord (using Ruby on Rails), if i have @products
variable where @products = Product.all
, and I say:
@products.where("name = 'check123' ")
, it returns an array of objects matching that condition, if i however go @products.where('name="check123"')
i get an error?
: SELECT "products".* FROM "products" WHERE (name = "check123")
Hirb Error: PG::UndefinedColumn: ERROR: column "check123" does not exist
LINE 1: SELECT "products".* FROM "products" WHERE (name = "check123"...
^
Why is this happening? It seems that I must always use double quotes around everything in the where clause and single quotes for any strings inside there ?
Shouldn't single quotes work here as well, or is there something Im not getting
Some other observations:
@products.where("cost = '23.0'")
works, event though 23 has a datatype of integer and not string?
@products.where('cost = 23')
works, so I know i can use single quotes inside the where clause
NOTE: I am aware of using the '?' syntax inside the where clause to avoid sql injections, I am purposefully trying to execute the query like this.