0

I have a staged file and I am trying to query the first line/row of it because it contains the column headers of the file. Is there a way I can create an external table using this file so that I can query the first line?

I am able to query the staged file using

SELECT a.$1
FROM @my_stage (FILE_FORMAT=>'my_file_format',PATTERN=>'my_file_path') a

and then to create the table I tried doing

CREATE EXTERNAL TABLE MY_FILE_TABLE
    WITH
        LOCATION='my_file_path'
        FILE_FORMAT = my_file_format;
jarlh
  • 42,561
  • 8
  • 45
  • 63
  • If the goal is to have clean syntax to read the header, would defining the query as a view meet your requirements? Defining it as an external table may be overkill depending on the requirements. – Greg Pavlik Jun 21 '22 at 19:15

1 Answers1

0

Reading Headers from CSV is not supported however this answer from StackOverflow gives a workaround.

Anshul Thakur
  • 484
  • 2
  • 5