Sub topic 5
Choosing which files to load with PATTERN and FILES
This chapter assumes you can write a basic COPY INTO statement, that you can read from a Unity Catalog volume or external location, and that you know what a Delta table is. Here you will learn how to narrow a load to a subset of the files in a source folder.
Why narrow the file list
By default, COPY INTO considers every file under the FROM path that matches the declared FILEFORMAT. Often that is too much. A landing folder may hold several months of files, test files, or files from other feeds. Two clauses let you restrict the load:
PATTERNselects files by a glob expression.FILESselects files by an explicit list of names.
You can use one or the other in a statement. They are mutually exclusive.
Selecting files with PATTERN
PATTERN takes a glob string. The pattern is matched against paths relative to the FROM location.
COPY INTO main.sales.orders
FROM '/Volumes/main/sales/landing/orders/'
FILEFORMAT = CSV
PATTERN = '2026-12-*.csv'
FORMAT_OPTIONS ('header' = 'true', 'delimiter' = ',');This loads only files such as 2026-12-01.csv and 2026-12-02.csv. Files from other months are ignored.
Common glob symbols:
| Symbol | Meaning | Example | Matches |
|---|---|---|---|
| `*` | Zero or more characters | `2026-*.csv` | `2026-12-01.csv` |
| `?` | Exactly one character | `part-?.csv` | `part-1.csv` |
| `[abc]` | One character from the set | `file-[ab].csv` | `file-a.csv` |
| `[a-c]` | One character from the range | `file-[0-3].csv` | `file-2.csv` |
| `{a,b}` | One of the alternatives | `{orders,returns}-*.csv` | `orders-1.csv` |
Patterns can also reach into subfolders, for example PATTERN = '2026/12/*/*.csv'.
Selecting files with FILES
Use FILES when you know exactly which files you want. The names are relative to the FROM path.
COPY INTO main.sales.orders
FROM '/Volumes/main/sales/landing/orders/'
FILEFORMAT = CSV
FILES = ('2026-12-01.csv', '2026-12-02.csv')
FORMAT_OPTIONS ('header' = 'true');FILES is useful when an upstream job tells you which files are new, or when you want to retry a specific set of files. The list is limited in size (up to 1000 file names), so use PATTERN for large selections.
How the selection fits into a load
Selection happens before the idempotency check. The command first builds the candidate list, then skips any candidate it has already loaded into this table.
Because of this order, a narrow selection never reloads old data by itself. It only decides which files are eligible.
Common errors
- Using both clauses. Supplying
PATTERNandFILESin the same statement fails. Pick one. - Putting the folder in the pattern. The
FROMpath already names the folder. WritePATTERN = '*.csv', not the full volume path. - Pattern matches nothing. The statement succeeds but loads zero rows. Check the result row counts (a later chapter covers reading results) and compare the pattern against actual file names with
LISTor by browsing the volume. - Wrong case. Glob matching is case-sensitive on object storage, so
*.CSVwill not matchorders.csv. - Expecting a pattern to change the format.
FILEFORMATstill decides how files are parsed. A pattern only filters names.
Exercise
A folder holds orders-2026-11-30.csv, orders-2026-12-01.csv, orders-2026-12-02.csv and returns-2026-12-01.csv. Write the clause that loads only the two December order files, and explain why FILES would be a poor choice if a new file arrives every day.
Show answer
Use PATTERN = 'orders-2026-12-*.csv'. The pattern picks up new December files automatically. With FILES you must list each name by hand, and the list is capped at 1000 names, so you would have to edit the statement each day.
Exercise
You run a statement with PATTERN = '2026-12-*.csv' twice in a row without adding any files. How many files does the second run load, and why?
Show answer
Zero. The pattern selects the same candidate files, but COPY INTO skips every file it already loaded into the table, so nothing new is written.