READ_CSV returns a table with data from the specified CSV file, where each cell is read as TEXT.
Syntax
AWS_ROLE_ARN, set the optional AWS_ROLE_EXTERNAL_ID to add a customer-controlled condition to your role’s trust policy.
For role-based AWS access you can additionally set an external ID. An external ID is a value you choose and control that AWS checks when Firebolt assumes your role, adding a second condition on top of your account’s unique IAM principal. Configuring one is a recommended best practice. See IAM roles.
Parameters
- The
URLalso accepts theupload://scheme to read a file sent in the same HTTP request. See Upload and query local files.
Return Type
The result is a table with the data from the CSV file. Each cell is read as aTEXT.
When loading multiple files, Firebolt infers the schema from the most recently modified file. The remaining files must have compatible data types. If types vary between files (e.g., a column contains integers in one file but doubles in another, or is numeric in one file but text in another), the inferred schema may not match all files and thus cause data type errors or query failures. In such cases, we recommend defining an explicit schema using either external tables or
COPY FROM into existing tables.Examples
Using LOCATION object
Best practice Firebolt recommends using aLOCATION 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:
PATTERN parameter with a location object to filter specific files:
This reads only the CSV files matching the pattern
levels* within the location’s base path, showing specific columns and the source file for verification.
Using static credentials
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:
*) 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:
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:
Example
The following example accepts
URL as a named parameter and reads a CSV file with column names in the first row:
Example
The following example reads a CSV with headers and reads empty values as empty strings, rather than
NULL values:
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: