The PostgreSQL INSERT INTO explanation permits one to embed new lines into a table. Each can embed a solitary column in turn or a few lines because of a question.
Fundamental linguistic structure of INSERT INTO articulation is as per the following −
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN) VALUES (value1, value2, value3,...valueN);
- Here, column1, column2,...columnN are the names of the segments in the table into which you need to embed information.
- The objective section names can be recorded in any request. The qualities provided by the VALUES provision or inquiry are related with the unequivocal or verifiable segment list left-to-right.
You should not indicate the column(s) name in the SQL inquiry on the off chance that you are adding values for all the segments of the table. Be that as it may, ensure the request for the qualities is in similar request as the segments in the table. The SQL INSERT INTO language structure would be as per the following −
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
The accompanying table sums up the yield messages and their importance −
|S. No.||Output Message & Description|
INSERT oid 1
Message returned if only one row was inserted. oid is the numeric OID of the inserted row.
INSERT 0 #
Message returned if more than one rows were inserted. # is the number of rows inserted.
Allow us to make COMPANY table in testdb as follows −
CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL, JOIN_DATE DATE );
The accompanying model embeds a line into the COMPANY table −
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY,JOIN_DATE) VALUES (1, 'Paul', 32, 'California', 20000.00,'2001-07-13');
The accompanying model is to embed a line; here compensation segment is overlooked and accordingly it will have the default esteem −
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,JOIN_DATE) VALUES (2, 'Allen', 25, 'Texas', '2007-12-13');
The accompanying model uses the DEFAULT statement for the JOIN_DATE section as opposed to indicating a worth −
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY,JOIN_DATE) VALUES (3, 'Teddy', 23, 'Norway', 20000.00, DEFAULT );
The accompanying model embeds different lines utilizing the multirow VALUES linguistic structure −
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY,JOIN_DATE) VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00, '2007-12-13' ), (5, 'David', 27, 'Texas', 85000.00, '2007-12-13');
All the above assertions would make the accompanying records in COMPANY table. The following part will show you how to show every one of these records from a table.
ID NAME AGE ADDRESS SALARY JOIN_DATE ---- ---------- ----- ---------- ------- -------- 1 Paul 32 California 20000.0 2001-07-13 2 Allen 25 Texas 2007-12-13 3 Teddy 23 Norway 20000.0 4 Mark 25 Rich-Mond 65000.0 2007-12-13 5 David 27 Texas 85000.0 2007-12-13