新的ruby,很难理解组合的ruby/sql语法(也很难google)

use*_*489 1 sql postgresql ruby-on-rails

我将不胜感激一些指向如何在ruby方法中的sql语句中解释一些可能微不足道的语法

基本上,功能就像

def foo(param)
  connection.execute(<<-SQL ... WHERE tablename.fieldname <@ '#{param.somefield}')
  other stuff...
end
Run Code Online (Sandbox Code Playgroud)

我假设'#{param.somefield}'只是在原始sql中输入param的"somefield"字段中的值,但我无法弄清楚"<@"的含义.似乎"<"可以是SQL中的字符串比较运算符,但是"@"在做什么?

谢谢!

arc*_*ana 5

<@与Ruby无关.它是一个SQL运算符range is contained by,用于postgresql中的范围类型.
https://www.postgresql.org/docs/current/static/functions-range.html