Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT CAST(u.id AS TEXT)
- FROM "user" u CROSS JOIN filter f
- JOIN "user" our ON our.id = :user_id
- WHERE f.user_id = :user_id
- -- Check other user's legitimacy
- AND u.is_fully_registered
- AND NOT u.is_permabanned
- AND NOT EXISTS (SELECT TRUE FROM match_exclusion me WHERE me.user_id=:user_id AND me.excluded_id = u.id)
- -- Check simple things
- AND ((u.birthday BETWEEN f.age_high AND f.age_low) OR f.age_high ISNULL OR f.age_low ISNULL)
- AND ((u.weight BETWEEN f.weight_low AND f.weight_high) OR f.weight_low ISNULL OR f.weight_high ISNULL)
- AND ((u.height BETWEEN f.height_low AND f.height_high) OR f.height_low ISNULL OR f.height_high ISNULL)
- AND (f.search_male AND u.is_male OR f.search_female AND NOT u.is_male)
- -- Check one-to-many array matching
- AND (f.educations = '{}' OR u.education = ANY (f.educations))
- AND (f.universities = '{}' OR u.university = ANY (f.universities))
- AND (f.religions = '{}' OR u.religion = ANY (f.religions))
- -- Check many-to-many array matching.
- AND (f.interests = '{}' OR (u.interests @> f.interests))
- AND (f.languages = '{}' OR (u.languages @> f.languages))
- ORDER BY st_distance(st_setsrid(st_point(u.longitude, u.latitude), 4326),
- st_setsrid(st_point(our.longitude, our.latitude), 4326)) NULLS LAST;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement