title: Missing Headers / Invalid Column Index errors with AWS S3 Select
body: <p>I am trying to make a select request from data stored in CSV format with AWS S3 <code>SelectObjectContent</code> and an SQL expression. I am working with Laravel 6.</p>
  <p>When I request all the data from the object (<code>'Expression' =&gt; 'SELECT * from S3Object'</code>), everything works fine. I retrieve the data and can work with it.
  The problem occurs when I want to use a <code>WHERE</code>-clause in the SQL expression.</p>
  <p>This is my code:</p>
  <pre><code>$client = new S3Client([
              'region' =&gt; 'us-east-2',
              'version' =&gt; 'latest',
          ]);
  
  
  $results = $client-&gt;selectObjectContent([
              'Bucket' =&gt; 'mybucketname', 
              'Key' =&gt; 'my_data_file.csv', 
              'ExpressionType' =&gt; 'SQL',
              'Expression' =&gt; 'SELECT * FROM S3Object s WHERE s.continent = &quot;Europe&quot;',
              'InputSerialization' =&gt; [
                  'CSV' =&gt; [
                      'FileHeaderInfo' =&gt; 'USE', 
                      'RecordDelimiter' =&gt; &quot;\n&quot;, 
                      'FieldDelimiter' =&gt; ',',
                  ],
              ], 
              'OutputSerialization' =&gt; [
                  'CSV' =&gt; [
                      'QuoteFields' =&gt; 'ASNEEDED',
                      'RecordDelimiter' =&gt; &quot;,&quot;,
                  ],
              ],
          ]);
  </code></pre>
  <p>I get the following error:</p>
  <pre><code>Error executing &quot;SelectObjectContent&quot;
  
  &lt;Error&gt;&lt;Code&gt;MissingHeaders&lt;/Code&gt;&lt;Message&gt;Some headers in the query are missing (truncated...) MissingHeaders (client): Some headers in the query are missing from the file. Please check the file and try again.
  </code></pre>
  <p>When I check the file (downloading it directly from the S3 bucket), in the first row I find the headers comma-separated, as I expected: <code>continent,country,user_name,created_at</code></p>
  <p>I also tried using positional headers and changed the expression to <code>'Expression' =&gt; 'SELECT * FROM S3Object s WHERE s._1 = &quot;Europe&quot;'</code> and <code>'FileHeaderInfo' =&gt; 'IGNORE'</code>, but that gave me another error:</p>
  <pre><code>Error executing &quot;SelectObjectContent&quot;
  
  &lt;Error&gt;&lt;Code&gt;InvalidColumnIndex&lt;/Code&gt;&lt;Message&gt;The column index at line 1, column (truncated...) InvalidColumnIndex (client): The column index at line 1, column 39 is invalid. Please check the service documentation and try again.
  </code></pre>
  <p>I am clueless how to proceed. I already saw this <a href="https://stackoverflow.com/questions/57476465/how-to-fix-missingheaders-error-while-appending-where-clause-with-s3-select">post</a>, but it didn't help. Maybe someone has a clue? Feel free to tell me what further information you could need for helping me solve this issue!</p>
  <p>Thanks in advance!</p>
  <p><strong>EDIT</strong></p>
  <p>I tried querying the csv file via the AWS console and everything works fine: The SQL expression in which I use the file header info as well as the one where I use the positional headers instead. Transferring the SQL expression in my controller I get the same errors I mentioned above:</p>
  <p><em>Missing Headers</em> for the query <code>'SELECT * FROM S3Object WHERE continent = &quot;Europe&quot;'</code> (and <code>'FileHeaderInfo' =&gt; 'USE'</code>)</p>
  <p><em>Invalid Column Index</em> for the query <code>'SELECT * FROM S3Object s WHERE s_1 = &quot;Europe&quot;'</code> (and <code>'FileHeaderInfo' =&gt; 'NONE'</code>)</p>