PostgreSQL VALUES Keyword
The PostgreSQL VALUES keyword is used to specify the values of an PostgreSQL INSERT INTO statement. There are two ways of using VALUES keyword which are mentioned below:
Syntax
The below syntax specifies column names and respective values to be inserted.
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
The below syntax specifies values only. Therefore, it is essential to specify values in the same order as the columns in the table.
INSERT INTO table_name VALUES (value1, value2, value3, ...);
Example:
Consider a database containing a table called Employee with the following records:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
-
Using below query, two new records are added in the Employee table:
INSERT INTO Employee (EmpID, Name, City, Age, Salary) VALUES (7, 'Suresh', 'Mumbai', 29, 2900); INSERT INTO Employee VALUES (8, 'Zayne', 'Oslo', 31, 3400); -- see the result SELECT * from Employee
Now the Employee table will contain following records:
EmpID Name City Age Salary 1 John London 25 3000 2 Marry New York 24 2750 3 Jo Paris 27 2800 4 Kim Amsterdam 30 3100 5 Ramesh New Delhi 28 3000 6 Huang Beijing 28 2800 7 Suresh Mumbai 29 2900 8 Zayne Oslo 31 3400 -
Insert Data Only in Specified Columns: To insert data in specified columns, it is necessary to specify column names. See the example below:
INSERT INTO Employee (EmpID, Name, Age) VALUES (7, 'Suresh', 29); -- see the result SELECT * from Employee
Now the Employee table will contain following records:
EmpID Name City Age Salary 1 John London 25 3000 2 Marry New York 24 2750 3 Jo Paris 27 2800 4 Kim Amsterdam 30 3100 5 Ramesh New Delhi 28 3000 6 Huang Beijing 28 2800 7 Suresh 29
❮ PostgreSQL Keywords