'SQL : Inserting multiple values in a single column

How can I save multiple values in my roles it should look like this :

enter image description here

I tried this query:

    export const insertIndividual = (data, result) => {
      db.query(
        "INSERT INTO individual (email, last_name, first_name, phone_number, password, 
suppress_email_sending, is_participant, org_id, suborgs, roles, created_at, modified_at, created_by, modified_by) 
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, [?], NOW(), NOW(), ?, ?)",
        [
          data.email,
          data.last_name,
          data.first_name,
          data.phone_number,
          data.password,
          data.suppress_email_sending,
          data.is_participant,
          data.org_id,
          data.suborgs,
          data.roles,
          data.created_by,
          data.modified_by,
        ],
        (err, results) => {
          if (err) {
            console.log(err);
            result(err, null);
          } else {
            result(null, results);
          }
        }
      );
    };

But I am getting this error:

enter image description here

How can I solve error?



Solution 1:[1]

You don't need the square brackets []. What you need is data.roles.toString() or data.roles.join(",") to convert an array to a string with the format you want.

Solution 2:[2]

I have solved this problem. I just enclosed the value of roles with 'single quotes'. Instead of [?], I used '?', is this a good approach, or does anyone has a better idea?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PhuriChal
Solution 2 Three_L_Some