v.23.6New Feature

Add TRUNCATE Modifier Support to INTO OUTFILE Clause

Add support for TRUNCATE modifier in INTO OUTFILE clause. Suggest using APPEND or TRUNCATE for INTO OUTFILE when file exists. #50950 (alekar).
Added support for the TRUNCATE modifier in the INTO OUTFILE clause to manage existing output files.

Why it matters

This feature addresses the need to control the behavior when exporting query results to a file using INTO OUTFILE. It allows users to explicitly choose whether to overwrite (truncate) the existing file or append to it, preventing unintentional data duplication or loss.

How to use it

When using the INTO OUTFILE clause in your SQL query, specify either the TRUNCATE or APPEND modifier to control file handling. For example:

SELECT * FROM table INTO OUTFILE 'file.csv' FORMAT CSV TRUNCATE;

This will overwrite the existing file. Alternatively, use APPEND to add to the file.