我想运行带有条件OR的PostgreSQL数据库查询命令以按ID数组过滤对象。
var id_arr = [1, 2, 3]
我想要得到的结果:
SELECT * FROM auth_user WHERE id = 1 OR id = 2 OR id = 3
我尝试过,但是出现语法错误:
var querydb = `SELECT * FROM auth_user WHERE ` + for (var i of id) { return id = i } + 'OR'
如何编写此代码?
答案 0 :(得分:1)
喜欢吗?
var ids = [1,2,3]
var querydb = `SELECT * FROM auth_user WHERE id IN (${ids})`;