← Back to team overview

maria-developers team mailing list archive

Re: UNION + INTO OUTFILE is confusing

 

Hi,


On 05/04/2016 12:52 AM, Alexander Barkov wrote:
Hi Sergei,


If I run this query:

SELECT 1 UNION SELECT 2 INTO OUTFILE 'test.txt';

It creates a file 'test.txt' with this content:

1
2

Looks fine so far.


Now if I do "rm test.txt" and execute another query (with parentheses):

(SELECT 1) UNION (SELECT 2 INTO OUTFILE 'test.txt');

it still puts the same two records from both UNION parts!
This looks confusing, as parentheses a kind of assume that only
the right UNION part is to be exported.

INTO @v1 is also confusing and is applied to the entire UNION,
rather than a UNION part:


(SELECT 1) UNION ALL (SELECT * FROM t1 LIMIT 1 INTO @v1);
ERROR 1172 (42000): Result consisted of more than one row




Exporting only one UNION part is not supported, IIRC.
So the above query should probably return a syntax error.


But now there is a new trouble. There is no syntax like this:

(SELECT ...) UNION (SELECT ...) INTO OUTFILE 'test.txt';



So instead of:

(SELECT ...) UNION (SELECT ... INTO OUTFILE 'test.txt');

one will have to write this:

SELECT * INTO OUTFILE 'test.txt'
FROM ((SELECT ...) UNION (SELECT ...)) AS t1;

The latter looks longer, but at least it's not confusing as the former.


References