Hi, Alexander! On May 04, Alexander Barkov wrote:
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.
Hardly. It'll break existing applications that export UNION result into a file. For no good reason.
But now there is a new trouble. There is no syntax like this:
(SELECT ...) UNION (SELECT ...) INTO OUTFILE 'test.txt';
This one we can support, perhaps. Or may be not, SELECT ... INTO is non-standard anyway, so I wouldn't bother...
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;
Regards, Sergei Chief Architect MariaDB and security@mariadb.org