Rails find_by_sql - use "?" literally, and not as a binding variable?

In the following, I want the first to ?be used literally, only the second ?should be used as a variable binding marker:

Foo.find_by_sql ["select IFNULL(col,'?') from foos where id = ?",1]

These errors are:

Incorrect number of binding variables (1 to 2)

How can I avoid the first ?one to be processed literally?

+4
source share
1 answer

ActiveRecord , , , ? in '?' , . - :

Foo.find_by_sql ["select IFNULL(col, '?') from foos where id = :id", :id => 1]

ActiveRecord , ( Ruby), placeal ? placeholders. , .

+4

Source: https://habr.com/ru/post/1660643/


All Articles