PostgreSQL unnest with empty array

前端 未结 5 1953
刺人心
刺人心 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:35

    select id,
        unnest (
            "values"
            ||
            (array[null]::integer[])[1:(array_upper("values", 1) is null)::integer]
        )
    from "table"
    

提交回复
热议问题