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

# INSERT

> Use the `INSERT` command to insert new rows into an existing table.

> [!NOTE]
>
> * For tables with primary keys, if you insert a row with an existing key, the new row will overwrite the existing row.
> * Call [FLUSH](https://docs.risingwave.com/sql/commands/sql-flush.md) after `INSERT` to persist the changes to storage. This ensures that the changes are committed and visible for subsequent reads.
> * If you only need the `INSERT` to wait until it is included in a successful checkpoint, you can enable [`DML_WAIT_PERSISTENCE`](https://docs.risingwave.com/sql/commands/sql-set-dml-wait-persistence). This does not provide the same immediate read-after-write visibility as `FLUSH`.

## Syntax

```sql theme={null}
INSERT INTO table_name [ ( col_name [ , ... ] ) ]
      { VALUES ( value [ , ... ] ) [ , ( ... ) ] | select_query }
      [ RETURNING col_name ];
```

## Parameters

| Parameter or clause | Description |
| :- | :- |
| *table\_name* | The table where you want to insert rows. |
| *col\_name* | The column where you want to insert corresponding values.  Currently, you must provide all columns in the table in order or leave this field empty. |
| *value* | An expression or value to assign to the corresponding column.  You can use [DESCRIBE](https://docs.risingwave.com/sql/commands/sql-describe.md) to check the order of the columns in the table. |
| *select\_query* | A [SELECT](https://docs.risingwave.com/sql/commands/sql-select.md) statement that returns the rows you want to insert to the table. |
| **RETURNING** | Returns the values of any column based on each inserted row. |

## Example

The table `taxi_trips` has three columns:

```sql theme={null}
{
  "id": INT NOT NULL,
  "distance": DOUBLE PRECISION NOT NULL,
  "city": VARCHAR
}
```

The following statement inserts four new rows into `taxi_trips`.

```sql theme={null}
INSERT INTO taxi_trips
    VALUES
      (1,16,'Dallas'),
      (2,23,'New York'),
      (3,6,'Chicago'),
      (4,9,NULL);
```

Let's query the table.

```sql theme={null}
SELECT * FROM taxi_trips ORDER BY id;
```

```bash theme={null}
 id | distance |   city
----+----------+----------
  1 |       16 | Dallas
  2 |       23 | New York
  3 |        6 | Chicago
  4 |        9 |
```

The following statement inserts all rows in another table name `taxi_trips_new` into `taxi_trips`. The two tables have the same column setup. Also, it returns the value of *id* for the inserted rows.

```sql theme={null}
INSERT INTO taxi_trips
    SELECT * FROM taxi_trips_new
    RETURNING id;
```


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