Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i would like to store multiple id's to the student_id column of users table. but it has the reference of departments table _id which is declared by int type so if you have any idea please suggest me

What I have tried:

db.query('INSERT INTO users(name,student_id) VALUES($1,ARRAY["$2","$3"]::INTEGER[]) RETURNING *', [data.name, data.id])
.then(function(user) { })
.catch(function(err) {
    return callback(null, err);
})
Posted
Updated 4-May-17 0:12am

1 solution

Don't, simple as that.
Even if the student_id column is a string based column - and that's the only way you will get multiple values in there, as a comma separated string - it's a PITA to work with from that moment on.
Instead, create a separate table which links the user ID to the StudentID and store one ID value pair per row. It's a whole load easier to work with when you need to refer to the data again.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900