> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

# READ_VORTEX

> Reference material for READ_VORTEX function

Preview

A table-valued function (TVF) that reads data from [Vortex](https://vortex.dev) files in object storage. The function can use either a location object (recommended) or direct credentials to access the data. `READ_VORTEX` returns a table with data from the specified Vortex files.

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
-- Using location object (recommended)
READ_VORTEX (
  LOCATION => 'location_name'
  [, PATTERN => <pattern>]
  [, SCHEMA => '<column_definitions>']
)
|
-- Using static credentials
READ_VORTEX (
  URL => <file_url>
  [, 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>]
  [, SCHEMA => '<column_definitions>']
)
```

When you pass `AWS_ROLE_ARN`, set the optional `AWS_ROLE_EXTERNAL_ID` to add a customer-controlled condition to your role's trust policy.

> [!NOTE]
>
> 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](https://docs.firebolt.io/security.md#iam-roles).

## Parameters

| Parameter | Description | Supported input types |
| :- | :- | :- |
| `LOCATION` | The name of a location object that contains the object storage 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](https://docs.firebolt.io/security/guides/location.md). | `TEXT` |
| `PATTERN` | When using `LOCATION`, an optional glob pattern to filter files within the location's URL path. The pattern is applied relative to the location's base path. For example, `PATTERN => 'week_1/*.vortex'` matches all `.vortex` files in the `week_1` subdirectory. | `TEXT` |
| `URL` | The location of your files, as `<scheme>://{bucket_name}/{full_file_path_glob_pattern}` with scheme `s3`, `gs`, or `azure`, or an array of such URLs to read several paths in one call. | `TEXT`, `ARRAY(TEXT)` |
| `AWS_ACCESS_KEY_ID` | The AWS access key ID. | `TEXT` |
| `AWS_SECRET_ACCESS_KEY` | The AWS secret access key. | `TEXT` |
| `AWS_SESSION_TOKEN` | The AWS session token. | `TEXT` |
| `AWS_ROLE_ARN` | The AWS role ARN. | `TEXT` |
| `AWS_ROLE_EXTERNAL_ID` | The AWS role external ID. | `TEXT` |
| `SCHEMA` | An explicit column schema, written as a comma-separated `CREATE TABLE` column list (no enclosing parentheses), for example `SCHEMA => 'id BIGINT, payload STRUCT(a INT, b TEXT)'`. When provided, schema inference is skipped and the files are read into the declared columns. Useful when the most recently modified file is not representative, or to read files with differing columns into one schema. See [Explicit schema](#explicit-schema). | `TEXT` |

* When using static credentials:
  * The `URL` can be passed as either the first positional parameter or a named parameter
  * If you provide either `AWS_ACCESS_KEY_ID` or `AWS_SECRET_ACCESS_KEY`, you must provide both
  * Providing an AWS session token is optional
  * Credentials are not required for accessing public buckets
* The `URL` also accepts the `upload://` scheme to read a file sent in the same HTTP request. See [Upload and query local files](https://docs.firebolt.io/reference-api/uploading-files.md).
* Where local file system access is enabled, the `URL` can be a local path: absolute, relative to the engine's working directory, or prefixed with `file://`.

## Return type

The result is a table with data from the Vortex files. Without `SCHEMA`, columns are read using data types inferred from the Vortex schema, and all columns are nullable.

> [!NOTE]
>
> **When loading multiple files, Firebolt infers the schema from the most recently modified file.** The remaining files must have compatible data types. If columns or types differ between files, pass an explicit `SCHEMA`.

## Explicit schema

With `SCHEMA`, every file is read into the declared columns:

* Columns are matched to file columns by name, case-sensitively. File columns not in the schema are not read.
* A declared column that is absent from a file reads as `NULL` for that file's rows. If the column is declared `NOT NULL`, it reads as its type's zero value (`0`, `''`, `false`) instead.
* A declared struct field that is absent from the file's struct reads the same way.
* A column whose declared type differs from the file's type is cast to the declared type. A value that cannot be cast fails the query.

## Best practice

Firebolt recommends using a `LOCATION` object to store credentials for authentication.

When using `READ_VORTEX()`, the URL parameter in the location should contain only Vortex files (see [location table-valued functions](https://docs.firebolt.io/security/guides/location.md#table-valued-functions-tvfs)).

## Examples

**Example**

The following code example reads the first 5 rows from Vortex files using a `LOCATION` object to store credentials for authentication:

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
SELECT *
FROM READ_VORTEX(
    LOCATION => 'my_vortex_location'
)
LIMIT 5;
```

**Example: Using location object with pattern**

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
CREATE LOCATION my_vortex_location WITH
  SOURCE = AMAZON_S3
  URL = 's3://my-bucket/events/';

SELECT $source_file_name, *
FROM READ_VORTEX(
    LOCATION => 'my_vortex_location', PATTERN => '2025-*/*.vortex'
)
LIMIT 5;
```

This reads only the Vortex files matching the pattern `2025-*/*.vortex` within the location's base path.

**Example: Reading files with differing columns into one schema**

`old.vortex` has columns `id` and `name`; `new.vortex` has `id`, `name`, and `score`. The declared schema covers both, and `score` is `NULL` for rows from `old.vortex`:

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
SELECT id, name, score
FROM READ_VORTEX(
    URL => ['s3://my-bucket/events/old.vortex', 's3://my-bucket/events/new.vortex'],
    SCHEMA => 'id BIGINT NULL, name TEXT NULL, score DOUBLE NULL'
);
```

### Using URL

* The `URL` can be passed as either the first positional parameter or a named parameter. For example, the following two queries both read the same file:

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
SELECT * FROM READ_VORTEX('s3://my-bucket/events/new.vortex');
SELECT * FROM READ_VORTEX(URL => 's3://my-bucket/events/new.vortex');
```

* The `URL` can represent a single file or a [glob](https://en.wikipedia.org/wiki/Glob_\(programming\)) pattern. If a glob pattern is used, all files matching the pattern are read. The special column `$source_file_name` identifies the source file of each row in the result set:

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
SELECT *, $source_file_name FROM READ_VORTEX('s3://my-bucket/events/*.vortex') LIMIT 5;
```

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 `*.vortex`, `date=2025*.vortex`, or `data_*.vortex`.

The pattern recursively matches files in all subdirectories.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.