How can I escape NULLs on mysql in batch mode?
In order to dump and reload some data, I use the mysql client with a select query (-e 'SELECT ...') in batch mode (to be more specific, is very silent mode, '-ss') directing the intermediate result to the stdout. In turn, the r开发者_如何学Cesult is then processed with LOAD DATA INFILE.
SELECT INTO OUTFILE is not an option, because there is not stdout redirection (if anybody has any tricks to perform this operation without using memory proportionally to the query result size, they are very welcome).
Now, the problem with '-ss -e' is that NULLs are outputted as 'NULL'.
Now, assuming the dataset doesn't have any value 'NULL' (string), I could do some sort of replace [with awk]. Or, without that assumption, I could use an IFNULL() using an extremely unlikely string that I would again replace [with awk].
What I'd want to know is: is there any way to do a 'clean' escaping directly from SQL? Apparently I can't get a '\N' in the output using IFNULL, because the slashes are escaped.
You can use NVL function to convert something in SQL from NULL to something else. http://www.techonthenet.com/oracle/functions/nvl.php
精彩评论