Postgresql将多维数组转换为关系模型

时间:2015-12-27 18:30:23

标签: postgresql multidimensional-array

我已多次看到此示例,但仅限于一列

INSERT INTO user_subservices(user_id, subservice_id) 
SELECT 1 id, x
FROM    unnest(ARRAY[1,2,3,4,5,6,7,8,22,33]) x

我需要使用多维数组插入多个列,如:

INSERT INTO items(order_id,lot_serial,pallets,oum) VALUES from Array

数组示例:

[[3,'Fff767',89,'Boxes'],[3,'FDH6784',45,'Boxes'],[3,'FDH6788',97,'Boxes']...]

使用Postgresql 9.4.5进行此操作的方法是什么

1 个答案:

答案 0 :(得分:1)

您可以创建reduce_dim函数以取消多维数组。 见https://wiki.postgresql.org/wiki/Unnest_multidimensional_array

{% set router = "<script src=\"{{ asset('bundles/fosjsrouting/js/router.js') }}\"></script>" %}
{{ include(template_from_string(router))}}