PostgreSQL. Consequently select results according with specific filters

I have a table with users.

User (that uses this programm) can select users by applying different filters. A filters must be applying immediatelly to reduce search time in final SELECT and no wasting time.

Currently my code looking like this (Python, not sure that this is working, not tested yet).

The question:

  1. How to applying a filters immediatelly as I get a user input?
  2. How to put/pass all actions related to filtering to DB?
if only_with_photo:     cursor.execute('SELECT tg_user_id FROM suers WHERE photo IS NOT NULL')     users_with_photo = cursor.fetchall() if only_with_country:     cursor.execute('SELECT tg_user_id FROM suers WHERE country IS NOT NULL')     users_with_country = cursor.fetchall() if only_with_city:     cursor.execute('SELECT tg_user_id FROM suers WHERE city IS NOT NULL')     users_with_city = cursor.fetchall()          cursor.execute('SELECT tg_user_id FROM users WHERE tg_user_id IN (users_with_photo) AND tg_user_id                              IN (users_with_country ) AND tg_user_id IN (users_with_city) ) 

Tasks: perform this queries inside psql without using Python or another language?

I tried:

  1. CASE sql = 'SELECT (CASE only_with_photo = 1 THEN (SELECT tg_user_id FROM users WHERE country IS NOT NULL)' --Subrequest returns more that one result
  2. Variables /set only_with_photo := (SELECT tg_user_id FROM users WHERE birthdate IS NOT NULL); --Syntax just now working