We can insert new rows into our tables by using INSERT
statement.
-- insert new row(user) into users table
INSERT INTO
users(datetime_joined, first_name, last_name, email, city, active)
VALUES
('2024-01-01 20:20:33', 'John', 'Moreno', '[email protected]', 'Berlin', true);
-- insert multiple rows
INSERT INTO
users(datetime_joined, first_name, last_name, email, city, active)
VALUES
('2024-01-01 20:20:33', 'John', 'Moreno', '[email protected]', 'Berlin', true),
('2024-01-01 20:20:33', 'Brent', 'Cox', '[email protected]', 'Amsterdam', true);
-- by puting `RETURNING *` at the end of insert statement
-- it returns inserted row back to you or show you in the console
INSERT INTO
users(datetime_joined, first_name, last_name, email, city, active)
VALUES
('2024-01-01 20:20:33', 'John', 'Moreno', '[email protected]', 'Berlin', true)
RETURNING *;