1. 数组连表查询
1
2
3
4
5
6
7
8
9
10
11
12
13
SELECT t.* FROM unnest(ARRAY[1,2,3,2,3,5]) item_id LEFT JOIN items t on t.id=item_id

# 或者
SELECT s.id sid, c.id cid, s.name sname, s.courses, c.name cname, c.e_name ce_name
FROM student s
LEFT JOIN course c ON c.id = ANY(s.courses)
ORDER BY s.id;

# 或者
SELECT s.id sid, c.id cid, s.name sname, s.courses, c.name cname, c.e_name ce_name
FROM student s
LEFT JOIN course c ON array[c.id] && s.courses
ORDER BY s.id;