Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:24:50+00:00 2026-06-13T22:24:50+00:00

I do not believe this question is a duplicate. I want rows in the

  • 0

I do not believe this question is a duplicate.

I want rows in the body to be “OPTIONALLY ENCLOSED BY” double quotes. Numerical values should not be enclosed. That’s easy to do without a header. But when you include a header using UNION, MySQL now treats every column as a string type and encloses all the values in quotes.

You can add a header to SELECT INTO OUTFILE like this:

SELECT "id", "numerical_values", "string_values" #header section of csv
UNION ALL
SELECT `id`, `numerical_values`, `string_values` #body section of csv
INTO OUTFILE "/tmp/values.csv"
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY "\n"
FROM `values_table`

Again, if I omit the header, only string_values will be enclosed by quotes.
With the header, all columns are seen as string columns and will be enclosed.

I tried this:

SELECT '"', "id", ',"', "numerical_values", ',"', "string_values", '"' 
#added quotes/commas to header
UNION ALL
SELECT `id`, ',', `numerical_values`, ',"', `string_values`, '"'
#added commas, and add quotes around string_values
INTO OUTFILE "/tmp/values.csv"
FIELDS TERMINATED BY "" ENCLOSED BY '' #empty values for fields terminated and enclosed
# empty because manually selected in query
LINES TERMINATED BY "\n" 
FROM `values_table`

I thought that would work, but I ended up with what looks like a bunch of extra whitespace. This is from an file I just created with the 2nd method. The header row ends at “string7”. The 1st line of data ends after “207”. I just put part of the 3rd line.

"         num1","                                          string1","       num2","                                          string2","       num3","                                                                        string3","       num4","                                                                        string4","       num5","                                                                        string5","       num6","                                                                        string6","      string7""
33.95     ," 1023                                         ",  7.50      ,"  207-1023                                     ",  26.95     ,"2 1023                                                                     ",23.00     ,"3Wx4Hx4D                                                                   ",19.00     ,"1023                                                                       ",  0.00      ,"UPC: 123456789012                                                          "," 207      "       
40.95     ," 1058                                         ",  9.00      ,
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:24:52+00:00Added an answer on June 13, 2026 at 10:24 pm
    SELECT '"id"', '"numerical_values"', '"string_values"'
    UNION ALL
    SELECT id, numerical_values, CONCAT('"', REPLACE(string_values, '"', '""'), '"')
    INTO OUTFILE '/tmp/values.csv'
    FIELDS TERMINATED BY ',' ENCLOSED BY '' ESCAPED BY '\\'
    LINES TERMINATED BY '\n'
    FROM values_table
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I believe , it's not a duplicate question. I don't want
I believe this is not a duplicate question, I have seen all questions/answers before
I hope this is not a duplicate of a question, but I have three
This may be duplicate question but I could not find one on SO. If
First of all, I don't believe my question is a duplicate of this .
Should links on a web page ALWAYS be underlined? I do not believe this
I cannot believe this question has not been asked before! Maybe I do not
First of all, I do not believe this belongs on Superuser. This belongs here
I Believe I'm doing this correctly but it is not getting the stored cookie
Despite working on EE for about 3 weeks now, believe it or not, this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.