A table-valued function (TVF) that reads CSV files from Amazon S3. The function can use either a location object (recommended) or direct credentials to access the data. READ_CSV returns a table with data from the specified CSV file, where each cell is read as TEXT.

Syntax

-- Using LOCATION object (recommended)
READ_CSV ( 
  LOCATION => 'location_name'
  [, COMPRESSION => <file_compression>]
  [, HEADER => { TRUE | FALSE }]
  [, DELIMITER => <field_delimiter>]
  [, QUOTE => { "'" | '"' | SINGLE_QUOTE | DOUBLE_QUOTE}]
  [, NULL_STRING => <null_string>]
  [, ESCAPE => <escape_character>]
  [, SKIP_BLANK_LINES => { TRUE | FALSE }]
  [, EMPTY_FIELD_AS_NULL => { TRUE | FALSE }]
  [, INFER_SCHEMA => { TRUE | FALSE }]
)
|
-- Using static credentials
READ_CSV ( 
  URL => <url>
  [, COMPRESSION => <file_compression>]
  [, AWS_ACCESS_KEY_ID => <aws_access_key_id>]
  [, AWS_SECRET_ACCESS_KEY => <aws_secret_access_key>]
  [, AWS_SESSION_TOKEN => <aws_session_token>]
  [, AWS_ROLE_ARN => <aws_role_arn>]
  [, AWS_ROLE_EXTERNAL_ID => <aws_role_external_id>]
  [, HEADER => { TRUE | FALSE }]
  [, DELIMITER => <field_delimiter>]
  [, QUOTE => { "'" | '"' | SINGLE_QUOTE | DOUBLE_QUOTE}]
  [, NULL_STRING => <null_string>]
  [, ESCAPE => <escape_character>]
  [, SKIP_BLANK_LINES => { TRUE | FALSE }]
  [, EMPTY_FIELD_AS_NULL => { TRUE | FALSE }]
  [, INFER_SCHEMA => { TRUE | FALSE }]
)

Parameters

ParameterDescriptionSupported input types
LOCATIONThe name of a location object that contains the Amazon S3 URL and credentials. Firebolt recommends using LOCATION to store credentials for authentication . LOCATION must be specified as a string literal (e.g., LOCATION => 'my_location'). Unlike URL, it cannot be used as a positional parameter. For a comprehensive guide, see LOCATION objects.TEXT
URLThe location containing your files in an Amazon S3 bucket. The expected format is s3://{bucket_name}/{full_file_path_glob_pattern}.TEXT
COMPRESSIONThe compression type of the input file. If compression is not set, compression is inferred from the file extension.TEXT
AWS_ACCESS_KEY_IDThe AWS access key ID.TEXT
AWS_SECRET_ACCESS_KEYThe AWS secret access key.TEXT
AWS_SESSION_TOKENThe AWS session token.TEXT
AWS_ROLE_ARNThe AWS role arn.TEXT
AWS_ROLE_EXTERNAL_IDThe AWS role external ID.TEXT
HEADERSet to TRUE if the first row of the CSV file contains a header row containing the column names.BOOL
DELIMITERSpecify the character used to separate fields. The default delimiter is a comma (,).TEXT
QUOTESpecify the character used for quoting fields. The default is double quote ("). If a single quote is specified, the quote character will be set to ('). Accepts only DOUBLE_QUOTE, SINGLE_QUOTE, ', or ".TEXT
NULL_STRINGSpecify the string used to represent NULL values. The default is an empty string, which means that empty strings are interpreted as NULL values.TEXT
ESCAPESpecify the character used to escape special characters. The default character is the quote (') character.TEXT
SKIP_BLANK_LINESSet to TRUE to ignore blank lines in the file.BOOL
EMPTY_FIELD_AS_NULLSpecify whether empty fields should be interpreted as NULL values. The default is TRUE. If set to FALSE, empty fields are interpreted as empty strings.BOOL
INFER_SCHEMASpecify whether column data types should be inferred from the data, instead of using TEXT.BOOL

Return Type

The result is a table with the data from the CSV file. Each cell is read as a TEXT.

Examples

Using LOCATION object

Best practice Firebolt recommends using a LOCATION object to store credentials for authentication. When using READ_CSV(), the URL parameter in the location should contain only CSV files (see location table-valued functions). The following code example reads a CSV file from the location specified by my_csv_location, treating the first row as a header containing column names:
SELECT * FROM READ_CSV(
    LOCATION => 'my_csv_location',
    HEADER => true
);

Using static credentials

SELECT * FROM READ_CSV(
    URL => 's3://firebolt-publishing-public/help_center_assets/firebolt_sample_dataset/levels.csv',
    HEADER => true
);
The url can represent a single file or a glob pattern. If a glob pattern is used, all files matching the pattern will be read. A special column $source_file_name can be used to identify the source file of each row in the result set:
SELECT *, $source_file_name FROM READ_CSV(
    URL => 's3://firebolt-publishing-public/help_center_assets/firebolt_sample_dataset/*.csv',
    HEADER => TRUE
);
When using glob patterns, the wildcard (*) can only be used at the end of the path. You can use it with any text before or after, such as *.csv, date=2025*.csv, or data_*.csv. The pattern will recursively match files in all subdirectories. For example:
SELECT * FROM READ_CSV('s3://firebolt-publishing-public/*.csv')
will read all CSV files in the bucket, including those in subdirectories like help_center_assets/firebolt_sample_dataset/*.csv. Example In the following example, the URL is set as the first positional parameter and reads a CSV file:
SELECT * FROM READ_CSV('s3://firebolt-publishing-public/help_center_assets/firebolt_sample_dataset/levels.csv');
Returns:
f0f1f2f3f4f5f6f7f8â€Ļ
LevelIDGameIDLevelNameLevelTypeNextLevelMinPointsToPassMaxPointsNumberOfLapsâ€Ļ
111Thunderbolt CircuitFastestLap25205â€Ļ
212Velocity ValeFirstToComplete3153010â€Ļ
313Raceway RidgeFastestLap4254020â€Ļ
414Nitro NarrowsFirstToComplete56010010â€Ļ
515Thunder RoadFirstToComplete68015015â€Ļ
616Burnout BoulevardDrift750808â€Ļ
717Speed StreetFastestLap840707â€Ļ
818Racing RavineFastestLap96010020â€Ļ
919Drift DistrictDrift1010025025â€Ļ
10110Acceleration AlleyFirstToCompletenull20050050â€Ļ
Example The following example accepts URL as a named parameter and reads a CSV file with column names in the first row:
SELECT * FROM READ_CSV(URL => 's3://firebolt-publishing-public/help_center_assets/firebolt_sample_dataset/levels.csv', 
        HEADER => true);
Returns
LevelIDGameIDLevelNameLevelTypeNextLevelMinPointsToPassMaxPointsNumberOfLapsâ€Ļ
11Thunderbolt CircuitFastestLap2520520â€Ļ
21Velocity ValeFirstToComplete315301010â€Ļ
31Raceway RidgeFastestLap425402020â€Ļ
41Nitro NarrowsFirstToComplete5601001010â€Ļ
51Thunder RoadFirstToComplete6801501515â€Ļ
61Burnout BoulevardDrift7508088â€Ļ
71Speed StreetFastestLap8407077â€Ļ
81Racing RavineFastestLap9601002020â€Ļ
91Drift DistrictDrift101002502525â€Ļ
101Acceleration AlleyFirstToCompletenull2005005050â€Ļ
Example The following example reads a CSV with headers and reads empty values as empty strings, rather than NULL values:
SELECT * FROM READ_CSV(URL => 's3://firebolt-publishing-public/help_center_assets/firebolt_sample_dataset/levels.csv',
        HEADER => true, EMPTY_FIELD_AS_NULL => false);
Returns:
LevelIDGameIDLevelNameLevelTypeâ€Ļ
11Thunderbolt CircuitFastestLap2â€Ļ
21Velocity ValeFirstToComplete3â€Ļ
31Raceway RidgeFastestLap4â€Ļ
41Nitro NarrowsFirstToComplete5â€Ļ
51Thunder RoadFirstToComplete6â€Ļ
61Burnout BoulevardDrift7â€Ļ
71Speed StreetFastestLap8â€Ļ
81Racing RavineFastestLap9â€Ļ
91Drift DistrictDrift10â€Ļ
101Acceleration AlleyFirstToCompleteâ€Ļ
Example The following example accepts URL as a named parameter, reads a CSV file with column names in the first row, and infers types for all columns. In this example it allows filtering using numeric comparisons, since the MaxPoints and MinPointsToPass columns are properly typed as numbers rather than strings:
SELECT * FROM READ_CSV(URL => 's3://firebolt-publishing-public/help_center_assets/firebolt_sample_dataset/levels.csv', 
        HEADER => true, INFER_SCHEMA => true) WHERE "MaxPoints" > 2 * "MinPointsToPass";
Returns
LevelIDGameIDLevelNameLevelTypeNextLevelMinPointsToPassMaxPointsNumberOfLapsâ€Ļ
11Thunderbolt CircuitFastestLap2520520â€Ļ
91Drift DistrictDrift101002502525â€Ļ
101Acceleration AlleyFirstToCompletenull2005005050â€Ļ