Berikut adalah CRUD pada PostgreSQL :
1. Insert
Format :
INSERT INTO TABLE_NAME
(column1, column2, column3, ……columnN) VALUES (value1, value2, value3, ….. valueN);
1.1. Insert Single
Format :
INSERT INTO table (column1, column2, ... ) DEFAULT VALUES;
Contoh :
INSERT INTO myschema."Student"(
"St_id", "St_Name", "St_age", "St_address", "St_blood_group")
1.2. Insert Multi Record
Format :
INSERT INTO table_name (column1, column2, ... )
SELECT expression1, expression2, ... FROM source_table [WHERE conditions];
Contoh :
INSERT INTO myschema."Student"(
"St_id", "St_Name", "St_age", "St_address", "St_blood_group")
VALUES(101, 'John', 24, 'New York', 'A+')
(102, 'Mike', 22, 'Chicago', 'B-'),
(103, 'Emily', 24, 'Boston', 'A-'),
(104, 'James', 20, 'Philadelphia', 'O+'),
(105, 'Sophia', 21, 'New York', 'B+');
2. Select
Format : SELECT select_list FROM table_name;
Contoh :
SELECT column1, column2, ……columnN FROM table_name;
3. Update
Format :
UPDATE table_name SET column1 = value1, column2 = value2....,
columnN = valueN WHERE condition;
Contoh :
UPDATE department SET last_update = DEFAULT
WHERE last_update IS NULL;
4. Delete
Format :
DELETE FROM table_name WHERE [condition];
DELETE FROM table USING another_table WHERE table.id = another_table.id AND
DELETE FROM table WHERE table.id = (SELECT id FROM another_table);
Contoh :
DELETE FROM department WHERE dept_id = 6;