katy
katy

Reputation: 15

Storing Array values to integer

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"
}

Upvotes: 1

Views: 134

Answers (1)

Vao Tsun
Vao Tsun

Reputation: 51511

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

Upvotes: 1

Related Questions