output hive query result as csv enclosed in quotes
<p>I have to export data from a hive table in a csv file in which fields are enclosed in double quotes.</p>

<p>So far I am able to generate a csv without quotes using the following query </p>

<pre><code>INSERT OVERWRITE DIRECTORY '/user/vikas/output'
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY ','
SELECT QUERY
</code></pre>

<p>The output generated looks like </p>

<pre><code>1,Vikas Saxena,Banking,JL5
</code></pre>

<p>However, I need the output as</p>

<pre><code>"1","Vikas Saxena","Banking","JL5" 
</code></pre>

<p>I tried changing the query to</p>

<pre><code>INSERT OVERWRITE DIRECTORY '/user/vikas/output'
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH SERDEPROPERTIES (
   "separatorChar" = ",",
   "quoteChar"     = "\"",
   "escapeChar"    = "\\"
)
SELECT QUERY
</code></pre>

<p>But it displays error</p>

<pre><code>Error while compiling statement: FAILED: ParseException line 1:0 cannot recognize input near 'ROW' 'FORMAT' 'SERDE'
</code></pre>