Select sum of an array column in PostgreSQL

后端 未结 3 1936
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 06:07

If I have the following table:

Table \"users\"
Column          |       Type       | Modifiers 
---------------+------------------+-----------
  id            | i         


        
3条回答
  •  梦毁少年i
    2021-02-05 06:56

    This generalization and reformatting Dmitry's answer helps me understand how it works:

    SELECT
      sum(a) AS total
    FROM
      (
        SELECT
          unnest(array [1,2,3]) AS a
      ) AS b
    

    Result:

    total
     6
    

提交回复
热议问题