Insert Into
Append rows to a table from a query, VALUES, or another table. Run it in a SQL paragraph, or in a Magpie paragraph as sql(INSERT INTO …). See Changing Table Data with SQL for where DML runs, which tables accept it, and worked examples.
Syntax
INSERT INTO [TABLE] <table> [PARTITION (<partition column> = <value> [, ...])] [(<column> [, ...])] <source>
INSERT INTO [TABLE] <table> [PARTITION (<partition column> = <value> [, ...])] [(<column> [, ...])]
FROM <relation> SELECT <columns> [WHERE ...] [GROUP BY ...] [ORDER BY ...] [LIMIT <n>]
where <source> is one of:
SELECT ... -- any query, including joins, UNION, ORDER BY, LIMIT
VALUES (<value>, ...) [, ...] -- literal rows
TABLE <source table> -- every row of another table
Parameters
table
String — The table to append to, as table or schema.table, in the current repository.
partition column and value
String, literal — Optional. A static partition: every inserted row gets this value for the column. The value must be a literal or a $variable; each column may appear once and must be a declared field of the table. Leave the partition column out of the source query. Partition columns you don't name are taken from the source.
column
String — Optional. A column list. Inserts are positional, so the list is accepted only when it repeats the table's declared column order exactly.
source
Query — The rows to insert. Its columns are written to the table's declared columns in order, so it must produce exactly as many columns as the table has, minus any static partition columns. WITH can't start the source directly; put the common table expression inside a subquery.
relation
String — The table to read in the FROM-first form, INSERT INTO t FROM s SELECT …. The SELECT must not have its own FROM.
Supported tables
Delta tables, tables on other file formats (Parquet, ORC, CSV, JSON, Avro, text; the partition layout is read from the col=value directories), and writable connector-backed tables (JDBC, Postgres, Redshift, Snowflake, BigQuery, Generic). PARTITION is supported on file-backed tables only.
Examples
-- append the result of a query
INSERT INTO analytics.daily_events
SELECT event_id, user_id, event_time
FROM staging.raw_events
WHERE event_date = '2026-07-21'
-- append literal rows
INSERT INTO reference.status_codes
VALUES (1, 'active'), (2, 'inactive')
-- static partition: every inserted row lands in region = 'us'
INSERT INTO sales.orders PARTITION (region = 'us')
SELECT order_id, customer_id, amount FROM staging.us_orders
-- FROM-first source
INSERT INTO analytics.big_customers
FROM sales.customers
SELECT customer_id, name
WHERE lifetime_value > 10000
-- copy a whole table
INSERT INTO backup.orders TABLE sales.orders
From a Magpie paragraph:
sql(INSERT INTO reference.status_codes VALUES (3, 'pending'))
Errors
Besides the common DML errors:
| Message | Cause |
|---|---|
INSERT column lists are only supported when they match the target's declared column order. … | The column list is not the table's declared order. |
INSERT source produces <n> columns, but target "<table>" expects <m> data columns (static partition columns are injected separately). | The source has the wrong number of columns. |
Static partition column '<column>' is also produced by the source query. Remove it from the SELECT or drop the PARTITION entry. | A static partition column is also in the source. |
Partition column "<column>" is not a declared field of table "<table>". | PARTITION names a column the table doesn't have. |
Dynamic partitioning is not supported; provide a value for partition column '<column>' … | PARTITION (<column>) without a value. |
Partition value for column '<column>' must be a literal or $variable; arbitrary expressions are not supported. | A partition value is an expression. |
INSERT with a PARTITION clause is not supported for table "<table>" (connector: <type>); PARTITION is only supported on file-backed tables. | PARTITION on a connector-backed table. |
A FROM-first INSERT source cannot contain a second FROM clause | The FROM-first form's SELECT has its own FROM. |
Security
Requires Write permission on the table and Read permission on every table the source reads.