INSERT Query in PostgreSQL

PostgreSQL INSERT To insert new records into a table the PostgreSQL INSERT statement is used.

Syntax:

INSERT into table_name(column_1, column_2, ... column_n )  
VALUES (value_1, value_2, .. value_n);  

Insert statement using UI: Other than Query tool, we can also INSERT statement in PostgreSQL using UI. To INSERT statement using UI in PostgreSQL, follow the below steps.

  • Right-click on the selected table.
  • Move your cursor over the option scripts.
  • Click on the “INSERT script” option.
  • Put the values on the place of “?”.
  • Click on the “play” button.

The query will thus be executed. To check the output, click on the table like structure and select the table.

Example 1: PostgreSQL INSERT single record insertion: Employment table before insertion:

ID STATE RATE
1 A 60
2 B 70
INSERT INTO “EMPLOYMENT”  
(“ID”, “STATE”, “RATE”)  
VALUES  
(3, 'C’, 65);

Explanation: The above query can be passed using the query tool. The EMPLOYMENT is an existing table in which we are adding a new row with corresponding values under the respective columns. The output will be like,

Employment table after insertion:

ID STATE RATE
1 A 60
2 B 70
3 C 65

Example 3: PostgreSQL INSERT multiple record insertion: Employment table before insertion:

ID STATE RATE
1 A 60
2 B 70
3 C 65
INSERT INTO “EMPLOYMENT”  
(“ID”, “STATE”, “RATE”)  
VALUES  
(4, 'D’, 80),
(5, 'E’, 78);

Explanation: The above query can be passed using the query tool. The EMPLOYMENT is an existing table in which we are adding two new rows with corresponding values under the respective columns. The output will be like,

Employment table after insertion:

ID STATE RATE
1 A 60
2 B 70
3 C 65
4 D 80
5 E 78
Please follow and like us:
Content Protection by DMCA.com