From 1e996f7fc4c406559b466ad692ef8a442f638cfc Mon Sep 17 00:00:00 2001 From: edvardchen <> Date: Mon, 28 Oct 2019 22:24:35 +0800 Subject: [PATCH] test: add integration tests for #3485 --- test/integration/builder/selects.js | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/integration/builder/selects.js b/test/integration/builder/selects.js index 6c89e47023..1cc117ee27 100644 --- a/test/integration/builder/selects.js +++ b/test/integration/builder/selects.js @@ -1380,5 +1380,38 @@ module.exports = function(knex) { } } }); + + it('select from subquery', async function() { + const subquery = knex.from('accounts').whereBetween('id', [3, 5]); + return knex + .pluck('id') + .orderBy('id') + .from(subquery) + .then( + (rows) => { + expect(rows).to.deep.equal([3, 4, 5]); + expect(knex.client.driverName).to.oneOf(['sqlite3', 'oracledb']); + }, + (e) => { + switch (knex.client.driverName) { + case 'mysql': + case 'mysql2': + expect(e.errno).to.equal(1248); + break; + case 'pg': + expect(e.message).to.contain('must have an alias'); + break; + + case 'mssql': + expect(e.message).to.contain( + "Incorrect syntax near the keyword 'order'" + ); + break; + default: + throw e; + } + } + ); + }); }); };