1

trying to store array values in integer . this is my code . is it wrong?

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);
})

but i am getting this error

{
 "name": "error",
 "length": 102,
 "severity": "ERROR",
 "code": "42703",
 "position": "70",
 "file": "parse_relation.c",
 "line": "3090",
 "routine": "errorMissingColumn"
}

1 Answer 1

1

42703 means undefined_column - this happens, because you use double quotes around "$2","$3" and double quotes are identifying db objects (in this part of the query - columns). Remove them to be:

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);
})
Sign up to request clarification or add additional context in comments.

6 Comments

yes i removed double quotes and i am getting like this You will need to rewrite or cast the expression
it means that ether $1 is of different data type then "name "column, or "student_id" column is not of integer[] data type. but that is totally different question
name column is character , but student_id is integer. i need to store multiple id's to student_id column so do you have any idea on Foreign key constraint for array-field ?
you can't put integer[] into integer. It's not about FK
ok actually 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
|

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.