I would like to write a Insert/Update query. I need to update tblnames2 based on tblenames3 and tblnames2 itself then insert the new rows where target name like inc table in target table field in tblnames1 based on tblnames2 by matching partial filename pattern.
tblNames1:
| application | job_name | desc | owner | author | cmd_line | target_table |
|---|---|---|---|---|---|---|
| abc | cde | test | test | test | bash $test/wrapper.sh --filename mbs/test.yaml --error 300 | test_inc.test |
| def | ghi | test1 | test1 | test1 | bash $test1/wrapper.sh --filename nkm/test1.yaml --error 300 | test_inc.test1 |
| hij | jkl | test2 | test2 | test2 | bash $test2/wrapper.sh --filename nkm/test2.yaml | test.test2 |
| klm | nop | test10 | test10 | test10 | bash $test2/wrapper.sh --filename test10.yaml | test.test10 |
tblNames2:
| filename | Description | target table |
|---|---|---|
| /app/data/shared/mbs/test.yaml | select * from test.fn_hierarchy_prod_group(1); | |
| /app/data/shared/nkm/test1.yaml | select *from run_update_query | |
| /app/data/shared/nkm/test5.yaml | select *from func_datad_addr_1 | |
| /app/data/shared/nkm/test2.yaml | INSERT INTO a_base(evnt_nbr,triggering_evnt,)SELECT evnt_nbr,triggering_evnt FROM delim; |
tblNames3:
|ID | Description | target table
|----|-----|----------------------
| 1082 | test.fn_hierarchy_prod_group | dba.l,dba.z
| 1091 | func_datad_addr | dba.n
| 1099 | fn_hierarchy_customer | dba.m
| 1100 | run_update_query | dba.j
Output - The query should return and update target - tblnames2 using 2 ways - i) by comparing description field(i.e function) of tablenames3 into tablenames2 and populate target table of tblnames3 into tblnames 2 ii) If its insert statement then populate the target after insert into tablename, pattern is not fixed though:
tblnames2 target table will be updated using tblenames3 and tblname2 itself:
| filename | Description | target table |
|---|---|---|
| /app/data/shared/mbs/test.yaml | select * from test.fn_hierarchy_prod_group(1); | dba.l |
| /app/data/shared/mbs/test.yaml | select * from test.fn_hierarchy_prod_group(1); | dba.z |
| /app/data/shared/nkm/test1.yaml | select *from run_update_query | dba.j |
| /app/data/shared/nkm/test5.yaml | select *from func_datad_addr_1 | |
| /app/data/shared/nkm/test2.yaml | INSERT INTO a_base(evnt_nbr,triggering_evnt,)SELECT evnt_nbr,triggering_evnt FROM delim; | a.base |
tblname1 - insert new rows based on target table using tblname2 wherever in target table of tblnames1 is inc for those records compare filename and check if any entry is present in tblname2:
| application | job_name | desc | owner | author | cmd_line | target_table |
|---|---|---|---|---|---|---|
| abc | cde | test | test | test | bash $test/wrapper.sh --filename mbs/test.yaml --error 300 | test_inc.test |
| def | ghi | test1 | test1 | test1 | bash $test1/wrapper.sh --filename nkm/test1.yaml --error 300 | test_inc.test1 |
| hij | jkl | test2 | test2 | test2 | bash $test2/wrapper.sh --filename nkm/test2.yaml | test.test2 |
| klm | nop | test10 | test10 | test10 | bash $test2/wrapper.sh --filename test10.yaml | test.test10 |
| abc | cde | test | test | test | bash $test/wrapper.sh --filename mbs/test.yaml --error 300 | dba.l |
| abc | cde | test | test | test | bash $test/wrapper.sh --filename mbs/test.yaml --error 300 | dba.z |
| def | ghi | test1 | test1 | test1 | bash $test1/wrapper.sh --filename nkm/test1.yaml --error 300 | dba.j |
| hij | jkl | test2 | test2 | test2 | bash $test2/wrapper.sh --filename nkm/test2.yaml | a_base |
I am new to postgres and have search different ways to update and insert it but I am not getting success. I have the basics but for this query I am not sure what to do if anyone pls help or guide.