Transforming Lake Data with Athena CTAS and INSERT INTO
This lesson explains how Athena SQL statements write results as new tables or files, so teams can convert, compact and aggregate lake data with SQL alone, without running Spark jobs.
Learning outcomes
After completing this lesson, you will be able to:
- Write data with CTAS, INSERT INTO and UNLOAD.
- Control format, compression and partitioning with CTAS properties.
- Work within the limits of CTAS, such as the 100-partition limit.
Statements that write data
Athena can write data as well as read it, which makes it a simple, serverless transformation tool. CREATE TABLE AS SELECT (CTAS) writes a query's results as a new table in Parquet or ORC, partitioned and bucketed as specified. That suits one-off format conversions and compacting small files. INSERT INTO appends results to an existing table, for example adding each day's aggregations. UNLOAD writes results to S3 in a chosen format without creating a table, for handing data to another system. For Apache Iceberg tables, MERGE, UPDATE and DELETE change rows, and OPTIMIZE and VACUUM maintain the table. The following table summarises the statements.
| Statement | Use |
|---|---|
| CREATE TABLE AS SELECT (CTAS) | Write query results as a new table in Parquet or ORC, partitioned and bucketed; good for one-off conversions and compaction |
| INSERT INTO | Append query results to an existing table, for example daily aggregations |
| UNLOAD | Write query results to S3 in a chosen format without creating a table |
| MERGE, UPDATE, DELETE, OPTIMIZE, VACUUM | Maintain Apache Iceberg tables |
Writing data with Athena
CTAS options
A CTAS statement controls the layout of the table it creates through its WITH properties, as the following example shows.
CREATE TABLE curated.sales_parquet
WITH (format = 'PARQUET', write_compression = 'SNAPPY',
external_location = 's3://lake/curated/sales/',
partitioned_by = ARRAY['sale_date'])
AS SELECT order_id, customer_id, amount, sale_date
FROM raw.sales_csv;A CTAS that is not partitioned
Limits
CTAS and INSERT INTO have limits that shape how they are used. A single statement can create at most 100 partitions. A conversion that spans more, for example two years of data partitioned by day, is split into batches: a CTAS statement for the first 100 partitions, followed by INSERT INTO statements that each add up to 100 more, such as one statement per quarter. Queries are also subject to Athena's query timeout, so very large transformations may not complete in one statement.
Athena is therefore best for one-off conversions, compaction and modest recurring transformations. For recurring, large transformations, AWS Glue or Amazon EMR jobs are usually a better fit, because they scale to larger volumes, add job scheduling and retries, and have no partition limit per run.
The following diagram shows a long conversion split into batches.

100partitions
Most a single CTAS or INSERT INTO statement creates
Partition limits
An analyst needs a one-off copy of three months of CSV clickstream data as partitioned Parquet for a project, and no engineering time is available to build a Glue job.
A CTAS statement converts the data to Parquet partitioned by date. Because there are about 90 daily partitions, the conversion fits within the 100-partition limit in one statement; for a longer period, the analyst would create the table with the first batch and add the rest with INSERT INTO.
Which Athena statement exports query results to S3?
Show answer
UNLOAD. CTAS creates a new table, and INSERT INTO appends to one.
Exam Tips
Remember for the exam
- CTAS converts data to partitioned Parquet; INSERT INTO appends; UNLOAD exports results.
- CTAS and INSERT INTO create at most 100 partitions per statement.
- Use CTAS for one-off conversions and compaction with SQL alone.
- Recurring large transformations suit Glue or EMR better than CTAS.
- OPTIMIZE and VACUUM maintain Iceberg tables from Athena.