Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow select from a union select #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sqlParser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
})

});