From 24486cdaa22958c3ae33acc2a67341cb3dbbd590 Mon Sep 17 00:00:00 2001 From: chack-os Date: Mon, 1 Aug 2022 19:42:45 -0600 Subject: [PATCH 1/2] allow in from a union select --- src/sqlParser.jison | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sqlParser.jison b/src/sqlParser.jison index 4a8efbc..a7abaef 100644 --- a/src/sqlParser.jison +++ b/src/sqlParser.jison @@ -587,6 +587,7 @@ index_hint table_factor : identifier partitionOpt aliasOpt index_hint_list_opt { $$ = { type: 'TableFactor', value: $1, partition: $2, alias: $3.alias, hasAs: $3.hasAs, indexHintOpt: $4 } } | '(' selectClause ')' aliasOpt { $$ = { type: 'TableFactor', value: { type: 'SubQuery', value: $2 }, alias: $4.alias, hasAs: $4.hasAs} } + | '(' unionClauseNotParenthesized ')' aliasOpt { $$ = { type: 'TableFactor', value: { type: 'SubQuery', value: $2 }, alias: $4.alias, hasAs: $4.hasAs} } | '(' table_references ')' { $$ = $2; $$.hasParentheses = true } ; place_holder From ad70ef17df70d6306becf814780190c473ed9fca Mon Sep 17 00:00:00 2001 From: chack-os Date: Mon, 1 Aug 2022 20:00:57 -0600 Subject: [PATCH 2/2] test select from a union select --- test/main.test.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/main.test.js b/test/main.test.js index 2ee9c1b..2029b83 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -436,4 +436,45 @@ describe('select grammar support', function () { it('test IDENTIFIER', function () { testParser('select `aa#sfs`(a) as \'A A\' from z'); }); + + it('test from with union select', function (){ + testParser(`select + (select min(actividad) + from + ( select client_id, + (select code_description from m_code_value where code_id =61 and id=LActividadEconomica_cd_own_business_main_activity) actividad, + estimated_amount_income_employer monto + from m_clientDetalleNegocios + union all + select client_id, + (select code_description from m_code_value where code_id =47 and id=Ltipoingreso_cd_income_type) actividad , other_incomes_estimated_amount monto + from m_clientDetalleOtrosIngresos + union all + select client_id, case r.Lsector_cd_Sector when 154 then 755 else 754 end actividad, + r.estimated_incomes_amount monto + from m_clientDetalleRelLaboral r + ) actividades + where monto = + ( select max(monto) + from + ( + select client_id, + (select code_description + from m_code_value where code_id =61 and id=LActividadEconomica_cd_own_business_main_activity) actividad, estimated_amount_income_employer monto + from m_clientDetalleNegocios + union all + select client_id, + (select code_description from m_code_value where code_id =47 and id=Ltipoingreso_cd_income_type) actividad , other_incomes_estimated_amount monto + from m_clientDetalleOtrosIngresos + union all + select client_id, case r.Lsector_cd_Sector when 154 then 755 else 754 end actividad, r.estimated_incomes_amount monto + from m_clientDetalleRelLaboral r + ) maxact + where client_id = actividades.client_id + ) + and client_id =cli.id + ) as c55017 + from m_client cli`) + }) + });