Svetan Dimoff Svetan Dimoff - 5 months ago 102
Node.js Question

NodeJS + PostgreSQL: INSERT has more target columns than expressions

I'd like to

INSERT
the current timestamp with
CURRENT_TIMESTAMP
on each new user registration. The column number equal the number of parameters in
VALUES
. Yet I get
INSERT has more target columns than expressions
. Using the
node-postgres
npm module as a controller.

//Just 3 parameters, timestamp is hardcoded in the query
exports.create = function (username, email, password) {
DB.connect(connection, function (err, client, done) {
var query = client.query(

//4 columns
"INSERT INTO users (username, email, userpass, datecreated) VALUES" +
//4 parameters
"(" + "'" + username + "'" + "," + "'" + email + "'" + "," + "'" + password + "'" + "'CURRENT_TIMESTAMP')");
query.on('error', function (error) {
console.log("query returned an " + error);
});
query.on('row', function (row, result) {
result.addRow(row);
});
});
};

Answer

Missing comma after password and no tics around current_Timestamp

"INSERT INTO users (username, email, userpass, datecreated) VALUES" +
    //4 parameters
    "(" + "'" + username + "'" + "," + "'" + email + "'" + "," + "'" + password + "," + "'CURRENT_TIMESTAMP)"
Comments