Question

I have to insert the data at a time in 3 tables into PostgreSQL database.

I have to insert data into first and Second table is directly.

But The third table which i received data as array and inserted into 3rd table as same.

Is data inserting as array into PostgreSQL available or possible?

If it possible how can I insert can some correct me How can i do the same mechanism with Wso2 DSS 3.0.1.

My query is

   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),?)
Was it helpful?

Solution

Not sure I understood your question exactly, but at least you could use 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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top