← Back to team overview

maria-developers team mailing list archive

UNION + INTO OUTFILE is confusing

 

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.

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.


Follow ups