eib*_*sji 0 ruby sql postgresql
我在ruby中有以下查询:
sql = "SELECT variants.id,
code,
regular_price,
price_before_sale
FROM variants
WHERE variants.code IN (#{context.codes.join(",")})"
Run Code Online (Sandbox Code Playgroud)
哪里 context.codes = ['PRDCT-1','PRDCT-2']
现在context.codes成为(PRDCT1,PRDCT2)sql查询中的对象,.join但是我想发生的是('PRDCT1','PRDCT2')我缺少什么?
EDI:我尝试过(#{context.codes.join("','")})但返回(PRDCT1','PRDCT2)
不要那样做 Bobby Tables在看着。而是提供足够数量的占位符:
sql = "SELECT variants.id,
code,
regular_price,
price_before_sale
FROM variants
WHERE variants.code IN (#{context.codes.map { "?" }.join(",")})"
Run Code Online (Sandbox Code Playgroud)
然后提供*context.codesin语句参数。