0
const deptCodes = ['001', '002', '003']

const getMembersQuery = {
   text: 'SELECT member_id FROM member_tbl WHERE dept_code IN ($1) AND delete_flg = 0',
   values: [deptCodes],
   rowMode: 'array'
};
    
const getMembersQuery Result = await client.query(getMembersQuery );

I am writing the above query but I am getting an error, malformed array literal: "001,002,003"\

3
  • literals require single quotes 001,002,003 should be '001','002','003' i.e. inside the SQL itself it needs those singles quotes Commented Oct 28, 2020 at 1:53
  • Can you suggest how should I format the deptCodes values? Commented Oct 28, 2020 at 2:22
  • you need to embed single quotes into the string to be evaluated by SQL so that one variable $1 can be interpreted as 3 separate stings each having a start and end single quote with commas between values. For this look at how you escape single quotes e.g. stackoverflow.com/questions/15087497/… Commented Oct 30, 2020 at 2:52

1 Answer 1

0

Try wrapping your depCodes in additional quotes

const deptCodes = ["'001'", "'002'", "'003'"]

or

const deptCodes = ['\'001\'', '\'002\'', '\'003\'']
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.