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

(Parser) support UNION #4962

Closed
pma-import opened this Issue Jan 28, 2003 · 13 comments

Comments

Projects
None yet
5 participants
@pma-import

pma-import commented Jan 28, 2003

Support UNION statements in the parser and correctly
split table references and select expressions.

- Original URL: https://sourceforge.net/p/phpmyadmin/feature-requests/262/
- Original author: lem9

@pma-import

This comment has been minimized.

pma-import commented Mar 5, 2003

- labels: —> Parsing
- milestone: —> Needs_planning

- Original author: garvinhicking

@pma-import

This comment has been minimized.

pma-import commented Feb 13, 2015

  • labels: Parsing --> Parsing, GSoC 2015

  • Original author: madhuracj
@pma-import

This comment has been minimized.

pma-import commented Feb 13, 2015

@pma-import

This comment has been minimized.

pma-import commented Feb 13, 2015

  • labels: Parsing, GSoC 2015 --> Parsing, gsoc

  • Original author: madhuracj
@pma-import

This comment has been minimized.

pma-import commented Feb 13, 2015

  • assigned_to: Marc Delisle

  • Original author: lem9
@pma-import

This comment has been minimized.

pma-import commented Mar 5, 2015

Where exactly do we need this? I mean after correctly splitting the select statements, where do we use/show it?


  • Original author: nisargjhaveri
@pma-import

This comment has been minimized.

pma-import commented Mar 6, 2015

Originally, this was for code highlighting. I just made a quick test and don't see a problem when browsing and sorting on a column coming from an UNION.

I guess you could not find anything either?


  • Original author: lem9
@pma-import

This comment has been minimized.

pma-import commented Mar 6, 2015

Found a problem which looks like a parser problem. Using the attached file, try
select supplier.city, supplier.id from supplier union select customer.city, customer.id from customer
then ask to sort on both columns (with shift+click on the second column).


@pma-import

This comment has been minimized.

pma-import commented Mar 16, 2015

This does not look like a parser problem.

I've created a separate ticket at https://sourceforge.net/p/phpmyadmin/bugs/4807/


  • Original author: nisargjhaveri
@pma-import

This comment has been minimized.

pma-import commented Mar 17, 2015

I accept your fix, but it could be a parser problem because the table name has not been determined.


  • Original author: lem9
@udan11

This comment has been minimized.

Member

udan11 commented Jul 25, 2015

Fixed in udan11/sql-parser@6e33561. It will be soon in the master branch too.

Tested with

select supplier.city, supplier.id from supplier union select customer.city, customer.id from customer

@lem9 lem9 closed this in 38368c4 Jul 26, 2015

@nijel nijel added the parser label Dec 16, 2015

@ghost ghost unassigned lem9 Feb 20, 2016

@deligant

This comment has been minimized.

deligant commented Jan 4, 2017

Don't know if the same error is the culprit, but if I do a complex UNION query, phpmyadmin 4.5.4.1deb2ubuntu2 (latest stable of 16.04 LTS) insertes a "limit 0,100" right after the UNION keyword
(and also does not parse correctly the REGEXP token...)

This original query:
(select DivId, ClId, TfId, TfName, TfDefault, TfRegExp, TfClasses, DivViewOrder, ClViewOrder from Divisions inner join Classes on DivTournament=ClTournament and DivAthlete=ClAthlete inner join TargetFaces Tf on DivTournament=TfTournament and concat(trim(DivId),trim(ClId)) REGEXP TfRegExp WHERE DivTournament=654 AND DivAthlete='1' AND (ClDivisionsAllowed='' or find_in_set(DivId, ClDivisionsAllowed))) UNION (select DivId, ClId, TfId, TfName, TfDefault, TfRegExp, TfClasses, DivViewOrder, ClViewOrder from Divisions inner join Classes on DivTournament=ClTournament and DivAthlete=ClAthlete inner join TargetFaces Tf on DivTournament=TfTournament and concat(trim(DivId),trim(ClId)) like TfClasses WHERE DivTournament=654 AND DivAthlete='1' AND (ClDivisionsAllowed='' or find_in_set(DivId, ClDivisionsAllowed))) order by DivViewOrder , ClViewOrder , TfDefault desc , TfRegExp>'' desc , concat(trim(DivId),trim(ClId)) = TfClasses desc , left(TfClasses,1)!='_' and left(TfClasses,1)!='%' desc , left(TfClasses,1)='_' desc , TfClasses desc , TfClasses='%'

results in 86 rows if executed directly in Mysql or in php, but in phpmyadmin I first get this error:
`Static analysis:

2 errors were found during analysis.

Unrecognized keyword. (near "REGEXP" at position 276)
Unexpected token. (near "TfRegExp" at position 283)
SQL query: Documentation

(select DivId, ClId, TfId, TfName, TfDefault, TfRegExp, TfClasses, DivViewOrder, ClViewOrder from Divisions inner join Classes on DivTournament=ClTournament and DivAthlete=ClAthlete inner join TargetFaces Tf on DivTournament=TfTournament and concat(trim(DivId),trim(ClId)) REGEXP TfRegExp WHERE DivTournament=654 AND DivAthlete='1' AND (ClDivisionsAllowed='' or find_in_set(DivId, ClDivisionsAllowed))) LIMIT 0, 100 UNION (

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION
(' at line 7`

Please note theat PhpMyadmin added the "LIMIT 0,100" string BEFORE the Union clause.
Amending the query (adding brackets around the regexp part) the error changes and is now

`SQL query: Documentation

(select DivId, ClId, TfId, TfName, TfDefault, TfRegExp, TfClasses, DivViewOrder, ClViewOrder
from Divisions
inner join Classes on DivTournament=ClTournament and DivAthlete=ClAthlete
inner join TargetFaces Tf on DivTournament=TfTournament and (concat(trim(DivId),trim(ClId)) REGEXP TfRegExp)
WHERE DivTournament=654
AND DivAthlete='1'
AND (ClDivisionsAllowed='' or find_in_set(DivId, ClDivisionsAllowed))) LIMIT 0, 100 UNION
(
MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION
(' at line 7`
Please notice the LIMIT 0,100 added before the UNION clause again!
To force it to work I need to add (!) a limit 0,1000 right before the closing bracket of the first select... wich is not a viable solution... especially because the same query was working perfectly with the version shipped with phpmyadmin in ubuntu 15.10!
I tried to force the limit after the order clause but without success!

@nijel

This comment has been minimized.

Member

nijel commented Jan 5, 2017

Might be same problem, there is also another bug this query exposes in our SQL parser: phpmyadmin/sql-parser#116

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment