Debug School

rakesh kumar
rakesh kumar

Posted on

How to delete particular row from postgress pgsql using commands

Enter PostgreSQL
Show all databases
Connect to a particular database
delete all rows from table

Enter PostgreSQL

sudo -u postgres psql
Enter fullscreen mode Exit fullscreen mode

Show all databases

Inside psql:

\l
Enter fullscreen mode Exit fullscreen mode

or:

\list
Enter fullscreen mode Exit fullscreen mode

Example:

hl_booking
hl_country
hl_profile
hl_trip
postgres
Enter fullscreen mode Exit fullscreen mode

Connect to a particular database

For example:

\c hl_booking
Enter fullscreen mode Exit fullscreen mode

You should see:

You are now connected to database "hl_booking".

Then show all tables:

\dt
Enter fullscreen mode Exit fullscreen mode

Suppose your table name is bookings.

delete all rows from table

To delete all rows but keep the table structure:

DELETE FROM availability_slots;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)