What is Returned by INSERT?
The INSERT...RETURNING
statement combines both INSERT
and SELECT
statements. It inserts one or more rows into a table and then returns a result containing the values of inserted rows depending upon the parameter.
After the RETURNING keyword, we can provide the column list or SELECT expression that specifies the columns to be returned. We can also use an asterisk (*) to get all the columns of the inserted rows.
Syntax:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...)
RETURNING [ * | column_list | SELECT expression ];
Explanation:
column_list
: You can directly provide the comma-separated list of columns whose values you want to retrieve from the inserted rows.
SELECT expression
: You can also provide only a SELECT expression that specifies the values to be returned. The SELECT keyword is not required, specify only the expression.
INSERT RETURNING in MariaDB
MariaDB, an open–source relational database management system, continues to evolve with new features and enhancements. One such feature introduced in version 10.5 is the INSERT…RETURNING statement, which offers a convenient and efficient way to insert data into a table and retrieve the inserted rows in a single operation.
This feature simplifies queries and saves time by eliminating the need for separate insert and select statements.
In this article, we will learn about everything about the INSERT…RETURNING with the help of examples and so on.