PostgreSQL INSERT Query

The INSERT Command allows one to insert rows in the table.One can insert a single row at a time or several rows.

PostgreSQL INSERT Syntax:

The syntax is as follows:

INSERT INTO table-name [(column1, column2, column3, ... columnN)]
VALUES
(value1, value2, value3, ... valueN);
-----------------------------------------------------------------
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);

Here column1, column2, column3, ... columnN is the name of the column and the value1, value2, value3, ... valueN is the value of the corresponding column.


OUTPUT:

1. INSERT oid 1:- This message return if only one row was inserted.oid is the numeric OID of the inserted row.
2. INSERT 0 #:- This message return if more than one row was inserted.# is known as the number of rows inserted.


INSERT Example :

Let us create STUDENT table in lfcdb as follows −

CREATE TABLE Student(
ID INT PRIMARY KEY     NOT NULL,
NAME           TEXT    NOT NULL,
AGE            INT     NOT NULL,
ADDRESS        CHAR(50)
);

Following example will add a new row in an table −

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS) VALUES (1, 'Rahul', 20, 'Mysore');
----------------------------------------------------------------------------
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS) VALUES (2, 'Kartik', 19, 'Delhi');
----------------------------------------------------------------------------
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS) VALUES (2, 'Nidhi', 21, 'Udaipur');

All the above statements would create the following records in STUDENT table

ID NAME AGE ADDRESS
1 Rahul 20 Mysore
2 Kartik 19 Delhi
3 Nidhi 21 Udaipur




Visit :


Discussion



* You must be logged in to add comment.