Perhaps this would be more SQL idiomatic:FROM permission p LEFT JOIN ON KEY role IN p AS r LEFT JOIN team_role AS tr ON KEY role TO r LEFT JOIN ON KEY team IN tr AS t LEFT JOIN user_role AS ur ON KEY role TO r LEFT JOIN ON KEY user IN ur AS u
FROM permission pLEFT JOIN role AS r ON [FOREIGN] KEY [(p.col1 [, p.col2 ...])]
pgsql-hackers by date:
Соглашаюсь с условиями обработки персональных данных