Search code examples
mysqlinsertapostrophe

Inserting apostrophes into mysql database


I have a CSV file structured on three text columns. Let's call them column A, B, C. In column A, I have free text that might include on several rows apostrophes.

I would like to create a mysql table that includes all the rows in the CSV file. How should I handle the apostrophes?

P.S. To create the mysql table, I plan to create insert queries using excel formulas.


Solution

  • From the web-site:

    There are several ways to include quote characters within a string:

    A “'” inside a string quoted with “'” may be written as “''”.

    A “"” inside a string quoted with “"” may be written as “""”.

    Precede the quote character by an escape character (“\”).

    A “'” inside a string quoted with “"” needs no special treatment and need not be doubled or escaped. In the same way, “"” inside a string quoted with “'” needs no special treatment.

    So either use two apostrophes or precede with backslash.

    EDIT: I see you say you are using Excel. I can tell you from experience it gets really confusing with the quote characters, especially as two single quotes can look like a double quote. It is probably better to use the backslash option in that case.