I'm working on porting a database system from PostgreSQL to mySQL but I can't get my head round this simply query?
The PostgreSQL query looks like the following:
query('WITH t as (UPDATE sessions SET expired = now() WHERE id = $1 AND ott = TRUE RETURNING *)' +
'SELECT * FROM users WHERE id = (SELECT user_id FROM t)',
[token], function(err, result) {
if (err) return callback(err);
if (result.rows === 0) return callback('NOT_VALID_TOKEN');
assert(result.rows.length === 1);
callback(null, result.rows[0]);
}
);
However when trying to write this into mySQL as such:
WITH t as (UPDATE sessions SET expired = now() WHERE id = 1 AND ott = TRUE RETURNING *) SELECT * FROM users WHERE id = (SELECT user_id FROM t)
It's throwing this:
1 errors were found during analysis.
Unrecognized statement type. (near "WITH" at position 0)