I have the following code:
SELECT * INTO OUTFILE'~/TestInput/Results.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
FROM Results;
Desired results are to continually keep on appending to Results.csv
I have the following code:
SELECT * INTO OUTFILE'~/TestInput/Results.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
FROM Results;
Desired results are to continually keep on appending to Results.csv
You can merge results and write at once. TEE will log everything which might not be desirable. In your case:
SELECT * FROM Results UNION
SELECT * FROM Results INTO OUTFILE '~/TestInput/Results.csv';
You can't do that with SELECT INTO OUTFILE
. That command only creates new files, and will fail if the file already exists.
You can append query output to an existing files using the TEE
command in the MySQL client.
Here's your example appending two query results to the same file using TEE
:
TEE ~/TestInput/Results.csv
SELECT *
FROM Results;
SELECT *
FROM Results;
NOTEE
It is not possible to do it directly in MySQL. But you may try to add date-time part into file name, then combine some files to a new one with a 'cat' (UNIX command) or 'type' (DOS command).
Help: cat (Unix)
Mysql 5.7 and beyond allows outfile to be a fifo file (mkfifo). You can run a script that reads from the fifo, as simple as cat myfifo myfifo myfifo myfifo myfifo myfifo ... >outfilefile. The fifo file needs as many open read close sequences as you'll execute select into outfile. Otherwise select into outfile does not allow overwriting or appending to an existing regular file.
© 2022 - 2024 — McMap. All rights reserved.