0

I want to run a PostgreSQL database query command with condition OR to filter object by an ID Array.

var id_arr = [1, 2, 3]

Result I want to get:

SELECT * FROM auth_user WHERE id = 1 OR id = 2 OR id = 3

I tried but it gets syntax error:

var querydb = `SELECT * FROM auth_user WHERE ` + for (var i of id) { return id = i } + 'OR'

How can I write this code?

1 Answer 1

1

Like this?

var ids = [1,2,3]
var querydb = `SELECT * FROM auth_user WHERE id IN (${ids})`;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.