Dump database to a script (.sql) file

Extract/Dump the database contents to a script (.sql) file

pg_dump -f ~/path/to/file.sql $YOUR_DATABASE_URL

Run a script (.sql) from file on a database

Run SQL commands from a file on a database

psql $YOUR_DATABASE_URL -f ~/path/to/file.sql

Check whether there is any row in the table matching your condition

select exists(select * from your_table where your_condition);

Have a great day people 👋