Say we create two tables (users and groups), where users are in groups:
create table users ( id int unique, name varchar unique ); create table groups ( id int unique, name varchar unique, member_users int, member_groups int );
The groups own the user memberships, rather than having an intermediate table with the relation.
Now, we want to join them, so we can simply do this:
select * from groups join users on users.id = ANY (groups.member_users)
2 Replies to “Postgres: JOIN on an array field”
Doesn’t work. “ERROR: operator does not exist: integer = integer”
Don’t forget the ANY operator.