PostgreSQL INSERT Command

When a table is created, it contains no data. To create a row in table, we use INSERT command. The insert command requires table name and column names.

Step1: Create table student.

CREATE TABLE student (
student_name varchar(80),
student_id int,
class int,
dob date
);

Insert data into table ‘student’:

insert into student values(‘Karunakar’,1001,1,’12-12-2015′);
insert into student values(‘varshini’,1002,2,’12-12-2014′);

or

insert into student(student_name,student_id,class,dob) values (‘Kalpesh’,1003,9,’12-09-2009′);
insert into student(student_name,student_id,class,dob) values (‘George’,1003,7,’02-10-2007′);

postgresql-truncate-command
PostgreSQL INSERT Command

Inserting multiple rows:

insert into student(student_name,student_id,class,dob) values (‘Michael’,1005,9,’12-09-2004′);
(‘Aravindh’,1006,6,’12-09-2005′);
(‘Jyothsna’,1007,4,’12-09-2006′);
(‘Kumar D’,1008,7,’12-09-2007′);

k2info=# select * from student;

 student_name | student_id | class |        dob         
--------------+------------+-------+--------------------
 Karunakar    |       1001 |     1 | 12-DEC-15 00:00:00
 varshini     |       1002 |     2 | 12-DEC-14 00:00:00
 Kalpesh      |       1003 |     9 | 12-SEP-09 00:00:00
 George       |       1003 |     7 | 02-OCT-07 00:00:00
 Michael      |       1005 |     9 | 12-SEP-04 00:00:00
 Michael      |       1005 |     9 | 12-SEP-04 00:00:00
 Aravindh     |       1006 |     6 | 12-SEP-05 00:00:00
 Jyothsna     |       1007 |     4 | 12-SEP-06 00:00:00
 Kumar D      |       1008 |     7 | 12-SEP-07 00:00:00
Powered by k2schools