好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

PostgreSql复合数组字段生成下标并文章字段的值

select aa.price,aa.type,aa.row_number from (

-- 生成下标并访问元素

SELECT 

    id,

    (pricerecord[idx]).price,  -- 通过下标访问复合字段

    (pricerecord[idx]).type,

    idx AS row_number      -- 直接使用下标作为行号

FROM 

    product.electricomponent,

    generate_subscripts(pricerecord, 1) AS idx  -- 生成一维数组的下标

)aa where type='purchase_price'  and id=2

-- 获取最后一个元素(通过数组长度计算下标)

SELECT    

    (pricerecord[array_length(pricerecord, 1)]).price AS newsprice

FROM product.electricomponent where id=12


查看更多关于PostgreSql复合数组字段生成下标并文章字段的值的详细内容...

  阅读:16次