【问题标题】:Inserting the data at a time in 3 tables using an array into Postgresql database使用数组将数据一次插入 3 个表中的 Postgresql 数据库
【发布时间】:2013-12-18 14:42:03
【问题描述】:

我必须一次将 3 个表中的数据插入 PostgreSQL 数据库。

我必须将数据插入第一个表,第二个表是直接的。

但是我以数组形式接收数据并插入到第三个表中的第三个表是一样的。

将数据作为数组插入 PostgreSQL 是否可用或可能?

如果可能的话,我该如何插入可以纠正我 如何使用 Wso2 DSS 3.0.1 执行相同的机制。

我的查询是

   with first_insert as (insert into sample(name,age)
                     values(?,?)
                  RETURNING id
),
second_insert as (insert into sample1(empid,desig)
                 values((select id from first_insert),?)
                 RETURNING userid
)

insert into sample2(offid,details)
          values((select userid from second_insert),?)

【问题讨论】:

    标签: sql postgresql wso2 wso2esb wso2dss


    【解决方案1】:

    不确定我是否完全理解您的问题,但至少您可以使用insert into ... select

    with cte_first_insert as
    (
        insert into sample1(name, age)
        values('John', 25)
        returning id
    ), cte_second_insert as (
        insert into sample2(empid, desig)
        select id, 1 from cte_first_insert
        returning userid
    )
    insert into sample3(offid, details)
    select userid, 'test'
    from cte_second_insert;
    

    sql fiddle demo

    【讨论】:

    • 嗨 Roman,我编辑了我的问题,请查看一次,我需要将数据作为数组直接存储到第三个表中。
    • 您能从我的 sqlfiddle 示例中提供所需的结果吗?
    • 对于第三个表 sample3,我收到的数组类型为 {1,2,3},现在我要将此数组直接存储到数据库中,或者如果可能我需要拆分值并存储到受尊重的列中。如果可能的话,请指导我如何插入。
    猜你喜欢
    • 2014-12-29
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多