PostgreSQL unnest with empty array

前端 未结 5 1955
刺人心
刺人心 2021-02-12 23:23

I use postgreSQL 9.1. In my database there is a table which looks like

id | ... | values
-----------------------
1  | ... | {1,2,3}
2  | ... | {}
5条回答
  •  醉话见心
    2021-02-12 23:29

    You will need to use self LEFT JOIN, like this (also on SQL Fiddle):

    SELECT t.id, u.u
      FROM tab t
      LEFT JOIN (SELECT id, unnest(vals) u FROM tab) u
        USING (id);
    

    Note, that for bigger tables query will be performing badly.

提交回复
热议问题