0

I've been thinking, might it be possible to dynamically change MySQL select-statement with variables.

ex.

SET @infile=1;
SELECT * 
IF( @infile )
INTO OUTFILE 'myfile.csv'
ENDIF
FROM my_table;

Or do I just have to go with my current solution

SELECT *
-- INTO OUTFILE 'myfile.csv'
FROM my_table;

So always when I want to load data into file, I'll just uncomment "INTO"-line. My statements are way bigger than this example, so solution would make life much easier, if possible :)

JesuZ
  • 1

1 Answers1

0

Consider creating views and then export from the view to a file when needed, e.g.,

CREATE VIEW `query1` AS select * FROM my_table;

IF (@infile)
   SELECT * INTO OUTFILE 'myfile.csv' FROM query1;
ELSE
   SELECT * FROM query1;
ENDIF
koriander
  • 3,110
  • 2
  • 15
  • 23
  • Unfortunately databases are mostly running with MySQL 4.1.9, so views are not supported. – JesuZ Mar 25 '13 at 11:58