且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Postgres:将单行转换为多行(不可透视)

更新时间:2022-12-07 07:54:35

带有 LATERAL $ c的单个 SELECT $ c>加入 VALUES 表达式即可完成工作:

A single SELECT with a LATERAL join to a VALUES expression does the job:

SELECT p.id, v.*
FROM   price_list p
     , LATERAL (
   VALUES
      ('type_a', p.price_type_a)
    , ('type_b', p.price_type_b)
    , ('type_c', p.price_type_c)
   ) v (price_type, price);

相关:

  • Convert one row into multiple rows with fewer columns
  • SELECT DISTINCT on multiple columns