Sub topic 11
Reloading already-loaded files with force
This chapter assumes you can write a basic COPY INTO statement, know how PATTERN and FILES select files, and understand that COPY INTO skips files it has already loaded. It covers the force option, which turns that skipping off. You will see what it does and why it is risky. You will also see safer ways to repair a bad load.
What force changes
By default, COPY INTO is idempotent. Idempotent means you can run the same statement repeatedly and get the same table. The command records which source files it has loaded into the target table. On the next run it skips those files and only loads new ones. A run with nothing new succeeds and inserts zero rows.
The force copy option removes that check. With 'force' = 'true', COPY INTO loads every file that matches the source path and any PATTERN or FILES filter. It does this whether or not the file was loaded before.
COPY INTO main.sales.orders
FROM '/Volumes/main/sales/landing/orders/'
FILEFORMAT = CSV
FORMAT_OPTIONS ('header' = 'true')
COPY_OPTIONS ('force' = 'true');The option is set in COPY_OPTIONS, not in FORMAT_OPTIONS. It is a copy option because it changes how the load behaves, not how files are parsed. The default is 'false'.
The statement above reads every file in the folder again and appends all the rows to main.sales.orders. COPY INTO does not compare the new rows with existing rows. It does not update or replace anything. It only appends.
Why force can create duplicates
Skipping files was the only protection against loading the same rows twice. Once you turn it off, nothing else prevents duplicates.
Suppose orders already holds 10,000 rows from three files. You run the forced statement over the same three files. The table now holds 20,000 rows, and every order appears twice. Downstream aggregates such as total revenue double, and joins on order_id fan out.
SELECT order_id, COUNT(*) AS copies
FROM main.sales.orders
GROUP BY order_id
HAVING COUNT(*) > 1;A query like this one finds duplicates after the fact. It only works if the table has a unique business key, such as order_id. If you cannot identify duplicates by key, the cleanup is much harder.
When force is the right tool
Reloading is a deliberate repair step. These are the usual reasons to use it.
- A source file was corrected in place. A producer fixes a bad export and overwrites a file with the same name. In typical use
COPY INTOidentifies files by path, so it treats the fixed file as already loaded and skips it. - You deleted rows and want them back. Someone ran a
DELETEon the table, or you removed a bad batch. The file history still says those files were loaded. - The first load used the wrong settings. For example, the wrong delimiter or a bad cast produced wrong values. You fix the statement and need to load the same files again.
- Testing. In a scratch table, forcing a reload lets you try a statement repeatedly on the same sample files.
In the first three cases, the old rows from the same files are usually still in the table, or you need to know that they are gone. You must decide what to do about them before forcing.
A safe reload pattern: delete, then force on specific files
The safest repair removes the stale rows first and then reloads only the affected files. For this to work, you need to know which rows came from which file. The SELECT-source technique from earlier chapters records this with _metadata.file_path.
Assume the table has a source_file column filled during loading:
COPY INTO main.sales.orders
FROM (
SELECT
CAST(order_id AS BIGINT) AS order_id,
CAST(amount AS DECIMAL(10, 2)) AS amount,
CAST(order_ts AS TIMESTAMP) AS order_ts,
_metadata.file_path AS source_file
FROM '/Volumes/main/sales/landing/orders/'
)
FILEFORMAT = CSV
FORMAT_OPTIONS ('header' = 'true');If 2026-12-03.csv was corrected upstream, do the repair in this order.
- Remove the stale rows that came from that file:
DELETE FROM main.sales.orders
WHERE source_file LIKE '%/2026-12-03.csv';- Preview the reload with
VALIDATEso you can check parsing without writing. TheVALIDATEclause comes before the options clauses, and it returns rows without changing the table:
COPY INTO main.sales.orders
FROM '/Volumes/main/sales/landing/orders/'
FILEFORMAT = CSV
FILES = ('2026-12-03.csv')
VALIDATE 10 ROWS
FORMAT_OPTIONS ('header' = 'true');- Run the real reload, limited to the one file:
COPY INTO main.sales.orders
FROM '/Volumes/main/sales/landing/orders/'
FILEFORMAT = CSV
FILES = ('2026-12-03.csv')
FORMAT_OPTIONS ('header' = 'true')
COPY_OPTIONS ('force' = 'true');- Check the counts. Compare the number of rows per source file with the number of data rows in the file:
SELECT source_file, COUNT(*) AS row_count
FROM main.sales.orders
WHERE source_file LIKE '%/2026-12-03.csv'
GROUP BY source_file;Using FILES (or a narrow PATTERN) keeps the blast radius small. Only the named file is read again. Every other file stays skipped as before, even though force is on.
If the source_file column does not exist, you have no cheap way to delete just one file's rows. Your options are then a key-based delete, a time-range delete, or rebuilding the table. This is a good reason to add _metadata.file_path to every load from the start.
What force does not do
- It does not deduplicate. It appends rows, and it does not match them to existing rows.
- It does not replace the table contents. For a full rebuild you could truncate or recreate the table and then load again. That is a different operation and has different risks.
- It does not look at modification time. It ignores history for every matching file, whether the file changed or not. So with force on a broad path, unchanged files are reloaded too.
- It does not change schema handling.
mergeSchema, type casts, and format options behave the same.
Related approaches to reloading
Force is not the only way to get data back into a table. Choose by the situation.
| Situation | Approach | Trade-off |
|---|---|---|
| A few files need to be reloaded and rows are tagged by file | Delete by `source_file`, then `FILES` plus `force` | Precise and cheap. Needs the file column. |
| Whole table is wrong and can be rebuilt | Recreate the target table, then run `COPY INTO` normally | Clean history, but the table loses its Delta history and any dependent grants or settings you do not recreate. |
| Rows are keyed and you want upserts | Load into a staging table, then `MERGE` into the target | More steps, but safe to repeat and no duplicates. |
| Many repeated reprocessing needs | Reconsider the design, for example Auto Loader with its own checkpoint | Different tool with its own reset procedure. |
The second row works because the record of loaded files belongs to the target table. A new table starts with no history, so a normal COPY INTO loads everything.
Checking the result of a forced load
COPY INTO returns a one-row result. It includes the number of rows affected and inserted, and the number of corrupt files skipped. After a forced reload of one file, num_inserted_rows should equal the number of data rows in that file. If it is larger, your FILES or PATTERN is matching more than you intended. Check this before running any downstream jobs.
Exercise
A teammate says: "A file was loaded with the wrong delimiter, so I'll just rerun the same COPY INTO with 'force' = 'true' and the right delimiter." The table has a source_file column. What is wrong with this plan, and what steps would you take instead?
Show answer
Force appends the rows again and does not remove the earlier bad rows, so the table would hold both the wrongly parsed rows and the correct ones. Also, force on the whole folder would reload every other file and duplicate those rows too. Instead: run DELETE FROM the table WHERE sourcefile matches the bad file, preview the corrected load with VALIDATE using FILES for that one file, then run COPY INTO with FILES set to that file and 'force' = 'true' and the corrected delimiter in FORMATOPTIONS. Finally compare the row count for that source_file with the file's data row count.