Insert data on table
18 May 2024 at 19:32
INSERT
Β statement to insert a new row into a table.
INSERT INTO table1(column1, column2, β¦) VALUES (value1, value2, β¦);
In this syntax:
- First, specify the name of the table (
table1
) that you want to insert data after theΒINSERT INTO
Β keywords and a list of comma-separated columns (colum1, column2, ....
). - Second, supply a list of comma-separated values in parenthesesΒ
(value1, value2, ...)
Β after theΒVALUES
Β keyword. The column and value lists must be in the same order.

RETURNING clause
- TheΒ
INSERT
Β statement has an optionalΒRETURNING
Β clause - returns the information of the inserted row.
INSERT INTO table1(column1, column2, β¦) VALUES (value1, value2, β¦) RETURNING *;

It return the inside table
We can return by any parameters.

Summary
- Use PostgreSQLΒ
INSERT
Β statement to insert a new row into a table. - Use theΒ
RETURNING
Β clause to get the inserted rows.