Enter PostgreSQL
Show all databases
Connect to a particular database
delete all rows from table
Enter PostgreSQL
sudo -u postgres psql
Show all databases
Inside psql:
\l
or:
\list
Example:
hl_booking
hl_country
hl_profile
hl_trip
postgres
Connect to a particular database
For example:
\c hl_booking
You should see:
You are now connected to database "hl_booking".
Then show all tables:
\dt
Suppose your table name is bookings.
delete all rows from table
To delete all rows but keep the table structure:
DELETE FROM availability_slots;
SELECT * FROM bookings;
SELECT * FROM bookings LIMIT 10;
SELECT *
FROM bookings
WHERE status = 'confirmed';
INSERT INTO bookings
(user_id, status)
VALUES
(10, 'pending'),
(11, 'confirmed'),
(12, 'cancelled');
UPDATE bookings
SET status = 'confirmed'
WHERE id = 10;
UPDATE bookings
SET
status = 'confirmed',
updated_at = NOW()
WHERE id = 10;
DELETE FROM bookings
WHERE id = 10;
DELETE FROM bookings
WHERE id = 10
RETURNING *;
To see all fields/columns of a particular PostgreSQL table, use:
## \d bookings
Top comments (0)