Search code examples
mysqlcsvexport-to-csvsequelpro

Export SQL result to CSV but retain the newline values in fields


I am trying to export a query result into CSV via Sequel Pro and I want to retain its newline values.

I tried escaping using REPLACE() and I also tried using other terminators such as ;.

My content looks like this

The word "adore" means to love something deeply. Other words that mean the same as adore are 
"cherish, treasure, love dearly" 

How can I export this data into CSV retaining the newline?

Please note that there is a whitespace character after the word are followed by a newline.


Solution

  • If I remember correctly, you can choose to use comma as delimiter, enclose a whole string content with " at the front and the end of string, escape the " with "" in your string, and that way you can retain your new line content.

    For example, instead of:

    The word "adore" means to love something deeply. Other words that mean the same as adore are 
    "cherish, treasure, love dearly" 
    

    Try changing above to:

    other_content_in_csv,"The word ""adore"" means to love something deeply. Other words that mean the same as adore are 
    ""cherish, treasure, love dearly"" ",other_content_in_csv