Bug #13863 Alternative INTO OUTFILE syntax not documented
Submitted: 8 Oct 2005 14:02 Modified: 25 Jan 2006 20:03
Reporter: Roland Bouman Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.0.13 OS:Windows (Win XP Professional SP2)
Assigned to: Paul DuBois CPU Architecture:Any

[8 Oct 2005 14:02] Roland Bouman
Description:
The Reference Manual states that the INTO OUTFILE clause should appear between the SELECT list and the FROM clause. However, I noticed that it is possible to append the INTO OUTFILE clause to the statement. 

By append, I mean that it can be placed after the FROM clause (if there's no GROUP BY, ORDER BY LIMIT), after the GROUP BY (if there's no ORDER BY and LIMIT), after the ORDER BY (if there's no LIMIT), or after the LIMIT. I did not systematically test all possibilities (I didnt try after GROUP BY, and I didn't try with the PROCEDURE clause) 

If this syntax is intentionally supported (and i really hope it is), this syntax should be documented.

How to repeat:
create table test (c int);

select *
from   test
into outfile 'D:\\temp\\example1.txt'
;
select c,count(*)
from   test
group by c
into outfile 'D:\\temp\\example2.txt'
;
select c,count(*)
from   test
group by c
limit 1
into outfile 'D:\\temp\\example3.txt'
;

Suggested fix:
Document this behaviour
[8 Oct 2005 15:17] MySQL Verification Team
Thank you for the bug report.

c:\mysql\bin>mysql -uroot test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 5.0.13-rc-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create table test (c int,name char(10));
Query OK, 0 rows affected (0.05 sec)

mysql> insert into test set c=1,name="mary";
Query OK, 1 row affected (0.00 sec)

mysql> insert into test set c=2,name="peter";
Query OK, 1 row affected (0.00 sec)

mysql> select * from test
    -> into outfile 'c:\\temp\\f1.txt';
Query OK, 2 rows affected (0.00 sec)

mysql> select * from test
    -> into outfile 'c:\\temp\\f2.txt'
    -> fields terminated by ','
    -> lines terminated by '\n';
Query OK, 2 rows affected (0.00 sec)

mysql> select * from test
    -> group by c limit 1
    -> into outfile 'c:\\temp\\f3.txt';
Query OK, 1 row affected (0.00 sec)
[25 Jan 2006 20:03] Paul DuBois
Thank you for your bug report. This issue has been addressed in the
documentation. The updated documentation will appear on our website
shortly, and will be included in the next release of the relevant
product(s).

Additional info:

The INTO clause can appear near the end of the SELECT
between the PROCEDURE and locking clauses (FOR UPDATE,
LOCK IN SHARE MODE).

I'll add a note to the effect that it can appear in either place
(as can INTO DUMPFILE).