DELETE FROM lgdat.stka WHERE v6stat = 'C';
DELETE FROM lgdat.stkmm where avtype = 'C';
DELETE FROM lgdat.stkmp where awtype = 'C';
DELETE FROM lgdat.icstm where cgtype = 'C';
DELETE FROM lgdat.icstp where chtype = 'C';
DELETE FROM lgdat.icstr where y0type = 'C';
WITH
repl AS (
    SELECT 
        *
    FROM 
        ( 
            VALUES
                ('GAB12000DE2','Garden Bowl - Slate Blue','GAB12000A34C012LRTOQ'),
                ('GAB14000DE2','Garden Bowl - Slate Blue','GAB14000A34C012LRTOT'),
                ('GAB18000DE2','Garden Bowl - Slate Blue','GAB18000A34C006LRTOW'),
                ('GAB22000DE2','Garden Bowl - Slate Blue','GAB22000A34C006LRTOZ'),
                ('GAB12000BG3','Garden Bowl - Teal','GAB12000A34C012LRTOQ'),
                ('GAB14000BG3','Garden Bowl - Teal','GAB14000A34C012LRTOT'),
                ('GAB18000BG3','Garden Bowl - Teal','GAB18000A34C006LRTOW'),
                ('GAB22000BG3','Garden Bowl - Teal','GAB22000A34C006LRTOZ'),
                ('CNA06000A42','Caribbean Planter - Warm Gray','CNA06000A50C024LRCGA'),
                ('CNA08000A42','Caribbean Planter - Warm Gray','CNA08000A50C024LRCGC'),
                ('CNA06000F89','Caribbean Planter - Raspberry','CNA06000A50C024LRCGA'),
                ('CNA08000F89','Caribbean Planter - Raspberry','CNA08000A50C024LRCGC'),
                ('CNA10000F89','Caribbean Planter - Raspberry','CNA10000A42C012LRBXI'),
                ('CNA12000F89','Caribbean Planter - Raspberry','CNA12000A42C012LRBXJ'),
                ('CNA06000BG3','Caribbean Planter - Teal','CNA06000A50C024LRCGA'),
                ('CNA08000BG3','Caribbean Planter - Teal','CNA08000A50C024LRCGC'),
                ('CNA10000BG3','Caribbean Planter - Teal','CNA10000A42C012LRBXI'),
                ('CNA12000BG3','Caribbean Planter - Teal','CNA12000A42C012LRBXJ'),
                ('CNA06000A10','Caribbean Planter - White','CNA06000A50C024LRCGA'),
                ('CNA08000A10','Caribbean Planter - White','CNA08000A50C024LRCGC'),
                ('CNA10000A10','Caribbean Planter - White','CNA10000A42C012LRBXI'),
                ('CNA12000A10','Caribbean Planter - White','CNA12000A42C012LRBXJ'),
                ('CNA30000A10','Caribbean Planter - White','CNA30000G18C002LRCDG'),
                ('LIA06000DE2','Classic Planter - Slate Blue','LIA06000A34C024LRTIV'),
                ('LIA08000DE2','Classic Planter - Slate Blue','LIA08000A34C024LRTIZ'),
                ('LIA10000DE2','Classic Planter - Slate Blue','LIA10000A34C012LRTJD'),
                ('LIA12000DE2','Classic Planter - Slate Blue','LIA12000A34C012LRTJH'),
                ('LIA14000DE2','Classic Planter - Slate Blue','LIA14000A34C012LRTJL'),
                ('LIA16000DE2','Classic Planter - Slate Blue','LIA16000A34C006LRTJP'),
                ('LIA20000DE2','Classic Planter - Slate Blue','LIA20000A34C006LRTJT'),
                ('LIA24000DE2','Classic Planter - Slate Blue','LIA24000A34C006LRTJY'),
                ('LIA06000B78','Classic Planter - Seafoam','LIA06000A34C024LRTIV'),
                ('LIA08000B78','Classic Planter - Seafoam','LIA08000A34C024LRTIZ'),
                ('LIA10000B78','Classic Planter - Seafoam','LIA10000A34C012LRTJD'),
                ('LIA12000B78','Classic Planter - Seafoam','LIA12000A34C012LRTJH'),
                ('LIA14000B78','Classic Planter - Seafoam','LIA14000A34C012LRTJL'),
                ('LIA16000B78','Classic Planter - Seafoam','LIA16000A34C006LRTJP'),
                ('LIA20000B78','Classic Planter - Seafoam','LIA20000A34C006LRTJT'),
                ('LIA24000B78','Classic Planter - Seafoam','LIA24000A34C006LRTJY'),
                ('SLI06000DE2','Classic Saucer - Slate Blue','SLI06000A34C024LRTKB'),
                ('SLI08000DE2','Classic Saucer - Slate Blue','SLI08000A34C024LRTKF'),
                ('SLI10000DE2','Classic Saucer - Slate Blue','SLI10000A34C012LRTKJ'),
                ('SLI12000DE2','Classic Saucer - Slate Blue','SLI12000A34C012LAH13'),
                ('SLI14000DE2','Classic Saucer - Slate Blue','SLI14000A34C012LAH16'),
                ('SLI17000DE2','Classic Saucer - Slate Blue','SLI17000A34C012LAH19'),
                ('SLI20000DE2','Classic Saucer - Slate Blue','SLI20000A34C006LAH24'),
                ('SLI24000DE2','Classic Saucer - Slate Blue','SLI24000A34C006LRTLD'),
                ('SLI06000B78','Classic Saucer - Seafoam','SLI06000A34C024LRTKB'),
                ('SLI08000B78','Classic Saucer - Seafoam','SLI08000A34C024LRTKF'),
                ('SLI10000B78','Classic Saucer - Seafoam','SLI10000A34C012LRTKJ'),
                ('SLI12000B78','Classic Saucer - Seafoam','SLI12000A34C012LAH13'),
                ('SLI14000B78','Classic Saucer - Seafoam','SLI14000A34C012LAH16'),
                ('SLI16000B78','Classic Saucer - Seafoam','SAA14001A10C006LRCDJ'),
                ('SLI20000B78','Classic Saucer - Seafoam','SLI20000A34C006LAH24'),
                ('SLI24000B78','Classic Saucer - Seafoam','SLI24000A34C006LRTLD'),
                ('ECA06000DE2','Eclipse Planter - Slate Blue','ECA06000A101009LRCIG'),
                ('ECA08000DE2','Eclipse Planter - Slate Blue','ECA08000A101006LRCID'),
                ('ECA10000DE2','Eclipse Planter - Slate Blue','ECA10000A341020LRCEL'),
                ('ECA12000DE2','Eclipse Planter - Slate Blue','ECA12000A101006LRCIA'),
                ('ECA16000DE2','Eclipse Planter - Slate Blue','ECA16000A34C010LRCEX'),
                ('ECA20000DE2','Eclipse Planter - Slate Blue','ECA20000A341006LRCEU'),
                ('ECA06000B78','Eclipse Planter - Seafoam','ECA06000A101009LRCIG'),
                ('ECA08000B78','Eclipse Planter - Seafoam','ECA08000A101006LRCID'),
                ('ECA10000B78','Eclipse Planter - Seafoam','ECA10000A341020LRCEL'),
                ('ECA12000B78','Eclipse Planter - Seafoam','ECA12000A101006LRCIA'),
                ('ECA16000B78','Eclipse Planter - Seafoam','ECA16000A34C010LRCEX'),
                ('ECA20000B78','Eclipse Planter - Seafoam','ECA20000A341006LRCEU'),
                ('GDP08000DE2','Hanging Garden Planter - Slate Blue','SAA14001A10C006LRCDJ'),
                ('GDP08000BG3','Hanging Garden Planter - Teal','SAA14001A10C006LRCDJ'),
                ('MSA12001DE2','Marina Planter - Slate Blue','MSA12001A341008LRCFQ'),
                ('MSA16001DE2','Marina Planter - Slate Blue','MSA16001A34C004LRAYN'),
                ('MSA20001DE2','Marina Planter - Slate Blue','MSA20001A34C004LRCFW'),
                ('MSA12001A42','Marina Planter - Warm Gray','MSA12001A341008LRCFQ'),
                ('MSA16001A42','Marina Planter - Warm Gray','MSA16001A34C004LRAYN'),
                ('MSA20001A42','Marina Planter - Warm Gray','MSA20001A34C004LRCFW'),
                ('MSA12001B78','Marina Planter - Seafoam','MSA12001A341008LRCFQ'),
                ('MSA16001B78','Marina Planter - Seafoam','MSA16001A34C004LRAYN'),
                ('MSA20001B78','Marina Planter - Seafoam','MSA20001A34C004LRCFW'),
                ('SEA07001DE2','Sedona Planter - Slate Blue','SEA07001B15C008LRAZR'),
                ('SEA09001DE2','Sedona Planter - Slate Blue','SEA09001B15C008LRAZS'),
                ('SEA12001DE2','Sedona Planter - Slate Blue','SEA12001B15C006LRAZU'),
                ('SEA14001DE2','Sedona Planter - Slate Blue','SEA14001B15C006LRAZT'),
                ('SEA16000DE2','Sedona Planter - Slate Blue','SAA14001A10C006LRCDJ'),
                ('SEA07001B78','Sedona Planter - Seafoam','SEA07001B15C008LRAZR'),
                ('SEA09001B78','Sedona Planter - Seafoam','SEA09001B15C008LRAZS'),
                ('SEA12001B78','Sedona Planter - Seafoam','SEA12001B15C006LRAZU'),
                ('SEA14001B78','Sedona Planter - Seafoam','SEA14001B15C006LRAZT'),
                ('SEA16000B78','Sedona Planter - Seafoam','SAA14001A10C006LRCDJ'),
                ('SEA07001A42','Sedona Planter - Warm Gray','SEA07001B15C008LRAZR'),
                ('SEA09001A42','Sedona Planter - Warm Gray','SEA09001B15C008LRAZS'),
                ('SEA12001A42','Sedona Planter - Warm Gray','SEA12001B15C006LRAZU'),
                ('SEA14001A42','Sedona Planter - Warm Gray','SEA14001B15C006LRAZT'),
                ('SEA16000A42','Sedona Planter - Warm Gray','SAA14001A10C006LRCDJ'),
                ('VNP18000A42','Venetian Flower Box - Warm Gray','VNP18000A34C006LRTPN'),
                ('VNP24000A42','Venetian Flower Box - Warm Gray','VNP24000A34C006LRTPR'),
                ('VNP30000A42','Venetian Flower Box - Warm Gray','VNP30000A34C006LRTPV'),
                ('VNP18000A10','Venetian Flower Box - White','VNP18000A34C006LRTPN'),
                ('VNP24000A10','Venetian Flower Box - White','VNP24000A34C006LRTPR'),
                ('VNP30000A10','Venetian Flower Box - White','VNP30000A34C006LRTPV'),
                ('SVN18000A42','Venetian Flower Box Tray - Warm Gray','SVN18000A34C006LRTPZ'),
                ('SVN24000A42','Venetian Flower Box Tray - Warm Gray','SVN24000A34C006LRTQD'),
                ('SVN30000A42','Venetian Flower Box Tray - Warm Gray','SVN30000A34C006LRTQH'),
                ('SVN18000A10','Venetian Flower Box Tray - White','SVN18000A34C006LRTPZ'),
                ('SVN24000A10','Venetian Flower Box Tray - White','SVN24000A34C006LRTQD'),
                ('SVN30000A10','Venetian Flower Box Tray - White','SVN30000A34C006LRTQH'),
                ('ASP06000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ'),
                ('ASP08000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ'),
                ('ASP10000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ'),
                ('ASP12000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ'),
                ('ASP16000P81','Aria Square Planter - Fresh Avocado','SAA14001A10C006LRCDJ'),
                ('ASP06000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('ASP08000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('ASP10000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('ASP12000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('ASP16000P80','Aria Square Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('ASP06000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('ASP08000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('ASP10000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('ASP12000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('ASP16000P26','Aria Square Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('ASP06000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ'),
                ('ASP08000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ'),
                ('ASP10000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ'),
                ('ASP12000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ'),
                ('ASP16000DE3','Aria Square Planter - Sapphire Blue','SAA14001A10C006LRCDJ'),
                ('ARP06000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ'),
                ('ARP08000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ'),
                ('ARP10000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ'),
                ('ARP12000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ'),
                ('ARP16000P81','Aria Round Planter - Fresh Avocado','SAA14001A10C006LRCDJ'),
                ('ARP06000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('ARP08000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('ARP10000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('ARP12000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('ARP16000P80','Aria Round Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('ARP06000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('ARP08000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('ARP10000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('ARP12000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('ARP16000P26','Aria Round Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('ARP06000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ'),
                ('ARP08000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ'),
                ('ARP10000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ'),
                ('ARP12000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ'),
                ('ARP16000DE3','Aria Round Planter - Sapphire Blue','SAA14001A10C006LRCDJ'),
                ('ANP12000A39','Aspen Planter - Charcoal','SAA14001A10C006LRCDJ'),
                ('ANP15000A39','Aspen Planter - Charcoal','SAA14001A10C006LRCDJ'),
                ('ANP17500A39','Aspen Planter - Charcoal','SAA14001A10C006LRCDJ'),
                ('CAS12000P26','Cascade Tall Square Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('CAS15000P26','Cascade Tall Square Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('CAS12000P80','Cascade Tall Square Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('CAS15000P80','Cascade Tall Square Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('CAR12000P26','Cascade Tall Round Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('CAR15000P26','Cascade Tall Round Planter - Black Onyx','SAA14001A10C006LRCDJ'),
                ('CAR12000P80','Cascade Tall Round Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('CAR15000P80','Cascade Tall Round Planter - Glossy White','SAA14001A10C006LRCDJ'),
                ('SKR12000G27','Santa Fe Round Planter - Black Sand','SAA14001A10C006LRCDJ'),
                ('SKR16000G27','Santa Fe Round Planter - Black Sand','SAA14001A10C006LRCDJ'),
                ('SKR12000E66','Santa Fe Round Planter - Cavern Clay','SAA14001A10C006LRCDJ'),
                ('SKR16000E66','Santa Fe Round Planter - Cavern Clay','SAA14001A10C006LRCDJ'),
                ('SKR12000A56','Santa Fe Round Planter - Pebble Gray','SAA14001A10C006LRCDJ'),
                ('SKR16000A56','Santa Fe Round Planter - Pebble Gray','SAA14001A10C006LRCDJ'),
                ('SKS12000G27','Santa Fe Square Planter - Black Sand','SAA14001A10C006LRCDJ'),
                ('SKS16000G27','Santa Fe Square Planter - Black Sand','SAA14001A10C006LRCDJ'),
                ('SKS12000E66','Santa Fe Square Planter - Cavern Clay','SAA14001A10C006LRCDJ'),
                ('SKS16000E66','Santa Fe Square Planter - Cavern Clay','SAA14001A10C006LRCDJ'),
                ('SKS12000A56','Santa Fe Square Planter - Pebble Gray','SAA14001A10C006LRCDJ'),
                ('SKS16000A56','Santa Fe Square Planter - Pebble Gray','SAA14001A10C006LRCDJ'),
                ('WBP16000P82','Whiskey Barrel Planter - Aged Oak','SAA14001A10C006LRCDJ'),
                ('0','Planter Trellis 6-Pack - Black','SAA14001A10C006LRCDJ')
        ) x("target","descr","clone")
)
,istka AS (
    INSERT INTO lgdat.stka
    SELECT
        repl.target v6part
        ,v6plnt
        ,v6unti
        ,v6rpln
        ,v6tpln
        ,v6tdys
        ,v6mrps
        ,v6abcc
        ,v6ccpy
        ,v6lcdt
        ,v6dbcc
        ,v6ordq
        ,v6opcy
        ,v6mult
        ,v6fut1
        ,v6fut2
        ,v6scdt
        ,v6plan
        ,v6cntr
        ,v6untp
        ,v6lvl
        ,v6pack
        ,v6pacu
        ,v6prpt
        ,v6kitc
        ,v6proc
        ,v6lrsp
        ,v6lrsc
        ,v6lrsf
        ,v6lrmp
        ,v6lrmc
        ,v6lrmf
        ,v6lwsp
        ,v6lwsc
        ,v6lwsf
        ,v6lcsp
        ,v6lcsc
        ,v6lcsf
        ,v6lcmp
        ,v6lcmc
        ,v6lcmf
        ,v6lssc
        ,v6lssf
        ,v6lsmp
        ,v6lsmc
        ,v6lsmf
        ,v6mpck
        ,v6mpku
        ,v6altf
        ,v6dbuy
        ,v6scdp
        ,v6selp
        ,v6rcps
        ,v6recu
        ,v6recc
        ,v6ftmf
        ,v6csmu
        ,v6ntky
        ,v6minq
        ,v6maxq
        ,v6moqt
        ,v6estv
        ,v6corg
        ,v6psor
        ,'C' v6stat
        ,v6reas
        ,v6auty
        ,v6unto
        ,v6reqc
        ,v6buyr
        ,v6lead
        ,v6optr
        ,v6multp
        ,v6minr
        ,v6perc
        ,v6ola
        ,v6mpqt
        ,v6dpst
        ,v6spdt
        ,v6bbdt
        ,v6orlt
        ,v6autr
        ,v6repp
        ,v6rept
        ,v6shrk
        ,v6fcfn
        ,v6auto
        ,v6olok
        ,v6oepy
        ,v6prfr
        ,v6cmtl
        ,v6drws
        ,v6drwl
        ,v6denc
        ,v6drel
        ,v6ddat
        ,v6drwn
        ,v6drws2
        ,v6drwl2
        ,v6denc2
        ,v6drel2
        ,v6ddat2
        ,v6drwn2
        ,v6lotf
        ,v6serf
        ,v6lotb
        ,v6lota
        ,v6lotv
        ,v6stcl
        ,v6vlcd
        ,v6sppp
        ,v6sppc
        ,v6mppp
        ,v6mppc
        ,v6frml
        ,v6istr
        ,v6engc
        ,v6revl
        ,v6rdat
        ,v6rcvlc
        ,v6sflc
        ,v6cusr
        ,v6cdat
        ,v6ctme
        ,v6uusr
        ,v6udat
        ,v6utme
        ,v6fut3
        ,v6fut4
        ,v6fut5
        ,v6flg1
        ,v6flg2
        ,v6flg3
        ,v6flg4
        ,v6flg5
        ,v6flg6
        ,v6flg7
        ,v6flg8
        ,v6flg9
        ,v6flg10
        ,v6fut6
        ,v6fut7
        ,v6fut8
        ,v6fut9
        ,v6fut10
        ,v6fut11
        ,v6fut12
        ,v6fut13
        ,v6fut14
        ,v6fut15
        ,v6fut16
        ,v6fut17
        ,v6fut18
        ,v6fut19
        ,v6fut20
        ,v6fut21
        ,v6fut22
        ,v6fut23
        ,v6fut24
        ,v6fut25
        ,v6fut26
        ,v6fut27
        ,v6fut28
        ,v6fut29
        ,v6fut30
        ,v6fut31
        ,v6fut32
        ,v6fut33
        ,v6fut34
        ,v6fut35
        ,v6fut36
        ,v6fut37
        ,v6fut38
        ,v6fut39
        ,v6fut40
        ,v6fut41
        ,v6fut42
        ,v6fut43
        ,v6fut44
        ,v6fut45
        ,v6prcl
        ,v6dbac
        ,v6scdpt
        ,v6apsup
        ,v6matp
        ,v6matm
        ,v6mesc
        ,v6crtm
        ,v6lled
        ,v6pctr
        ,v6inqu
        ,v6clexp
    FROM
        repl
        INNER JOIN lgdat.stka ON
            v6part = repl.clone
    RETURNING *
)
, istkmm AS (
    INSERT INTO lgdat.stkmm
    SELECT
        repl.target avparta
        ,repl.descr avdes1
        ,avdes2
        ,avdes3
        ,avunti
        ,avmajg
        ,avming
        ,avmajs
        ,avmins
        ,avglcd
        ,avgled
        ,avharm
        ,avclss
        ,avfut3
        ,avfut4
        ,avfut5
        ,avfutc
        ,avfutd
        ,avupcc
        ,avgtin
        ,avnwht
        ,avnwun
        ,avsvol
        ,avsvun
        ,avengc
        ,avrevl
        ,avrdat
        ,avcoil
        ,avfut9
        ,avmspc
        ,avslif
        ,avdplt
        ,avuver
        ,avcata
        ,avfedc
        ,avtaxr
        ,avcust
        ,"avcpt#"
        ,"avrev#"
        ,avfut7
        ,avfut8
        ,avfutb
        ,avldat
        ,'C' avtype
        ,avfutk
        ,avfutn
        ,avppap
        ,avcusr
        ,avcdat
        ,avctme
        ,avuusr
        ,avudat
        ,avutme
        ,avsizc
        ,avstlc
        ,avcolc
        ,avassc
        ,avsasc
        ,avlcoil
        ,avgdfl
        ,avvdfl
        ,avwoqf
        ,avnmfc
        ,avfuth
        ,avfuti
        ,avfutl
        ,avfutm
        ,avfutp
        ,avfutq
        ,avfutr
        ,avprun
        ,avtotp
        ,avdisc
        ,avinvt
        ,avbk01
        ,avbill
        ,avbk04
        ,avbk06
        ,avoldd
        ,avoldd2
        ,avlotf
        ,avserf
        ,avorig
        ,avplan
        ,avminq
        ,avmaxq
        ,avlead
        ,avscdt
        ,avestv
        ,avcntr
        ,avuntp
        ,avlvl
        ,avmoqt
        ,avpack
        ,avpacu
        ,avprpt
        ,avkitc
        ,avproc
        ,avlrsp
        ,avlrsc
        ,avlrsf
        ,avlrmp
        ,avlrmc
        ,avlrmf
        ,avlwsp
        ,avlwsc
        ,avlwsf
        ,avlcsp
        ,avlcsc
        ,avlcsf
        ,avlcmp
        ,avlcmc
        ,avlcmf
        ,avlssc
        ,avlssf
        ,avlsmp
        ,avlsmc
        ,avlsmf
        ,avmpck
        ,avmpku
        ,avaltf
        ,avdbuy
        ,avfut1
        ,avfut2
        ,avfut6
        ,avfuta
        ,avfutg
        ,avrecu
        ,avftmf
        ,avrecc
        ,avfutj
        ,avabcc
        ,avcorg
        ,avperc
        ,avoptr
        ,avmult
        ,avminr
        ,avshrk
        ,avstat
        ,avreas
        ,avspdt
        ,avbbdt
        ,avpsor
        ,avfuto
        ,avdrws
        ,avdrwl
        ,avdenc
        ,avdrel
        ,avddat
        ,avfute
        ,avdrws2
        ,avdrwl2
        ,avdenc2
        ,avdrel2
        ,avddat2
        ,avfutf
        ,avstcl
        ,avvlcd
        ,avsppp
        ,avsppc
        ,avmppp
        ,avmppc
        ,avflg01
        ,avflg02
        ,avflg03
        ,avflg04
        ,avflg05
        ,avflg06
        ,avflg07
        ,avflg08
        ,avflg09
        ,avflg10
        ,avfut01
        ,avfut02
        ,avfut03
        ,avfut04
        ,avfut05
        ,avfut06
        ,avfut07
        ,avfut08
        ,avfut09
        ,avfut10
        ,avfut11
        ,avfut12
        ,avfut13
        ,avfut14
        ,avfut15
        ,avfut16
        ,avfut17
        ,avfut18
        ,avfut19
        ,avfut20
        ,avfut21
        ,avfut22
        ,avfut23
        ,avfut24
        ,avfut25
        ,avfut26
        ,avfut27
        ,avfut28
        ,avfut29
        ,avfut30
        ,avfut31
        ,avfut32
        ,avfut33
        ,avfut34
        ,avfut35
        ,avfut36
        ,avfut37
        ,avfut38
        ,avfut39
        ,avfut40
        ,avfut41
        ,avfut42
        ,avfut43
        ,avfut44
        ,avfut45
        ,avudft
        ,avfrml
        ,avhaza
        ,avlled
        ,avdbac
        ,avscdpt
        ,avfifo
        ,avantid
        ,avsubt
        ,avprcl
        ,avotp
        ,avcbyl
        ,avsrvc
        ,avspal
        ,avpgrp
    FROM
        repl
        INNER JOIN lgdat.stkmm m ON
            m.avpart = repl.clone
    RETURNING *
)
, istkmp AS (
    INSERT INTO lgdat.stkmp
    SELECT
        repl.target awpart
        ,repl.descr awdes1
        ,awdes2
        ,awdes3
        ,awunti
        ,awmajg
        ,awming
        ,awmajs
        ,awmins
        ,awgldc
        ,awgled
        ,awharm
        ,awclss
        ,awfut3
        ,awfut4
        ,awfut5
        ,awfutc
        ,awfutd
        ,awupcc
        ,awgtin
        ,awnwht
        ,awnwun
        ,awsvol
        ,awsvun
        ,'C' awtype
        ,awvend
        ,"awvpt#"
        ,"awrev#"
        ,awengc
        ,awrevl
        ,awrdat
        ,awfut7
        ,awfut8
        ,awfutb
        ,awcoil
        ,awfut9
        ,awmspc
        ,awuver
        ,awcata
        ,awslif
        ,awfutk
        ,awfutn
        ,awppap
        ,awdplt
        ,awgdfl
        ,awvdfl
        ,awwoqf
        ,awlcoil
        ,awnmfc
        ,awsizc
        ,awstlc
        ,awcolc
        ,awassc
        ,awsasc
        ,awcusr
        ,awcdat
        ,awctme
        ,awuusr
        ,awudat
        ,awutme
        ,awfuth
        ,awfuti
        ,awfut6
        ,awfutl
        ,awfutm
        ,awfuto
        ,awfutp
        ,awfutq
        ,awfutr
        ,awldat
        ,awlotf
        ,awserf
        ,awoldd
        ,awbk02
        ,awoldd2
        ,awdisc
        ,aworig
        ,awfedc
        ,awtaxr
        ,awbk01
        ,awbk03
        ,awbk04
        ,awbk05
        ,awinvt
        ,awconv
        ,awunto
        ,awreqc
        ,awoptr
        ,awlead
        ,awcorg
        ,awcntr
        ,awola
        ,awuntp
        ,awshrk
        ,awlvl
        ,awmoqt
        ,awpack
        ,awpacu
        ,awprpt
        ,awbuyr
        ,awauty
        ,awmpqt
        ,awabcc
        ,awstat
        ,awproc
        ,awlrsp
        ,awlrsc
        ,awlrsf
        ,awlrmp
        ,awlrmc
        ,awlrmf
        ,awlwsp
        ,awlwsc
        ,awlwsf
        ,awlcsp
        ,awlcsc
        ,awlcsf
        ,awlcmp
        ,awlcmc
        ,awlcmf
        ,awlssc
        ,awlssf
        ,awlsmp
        ,awlsmc
        ,awlsmf
        ,awmpck
        ,awmpku
        ,awfutj
        ,awfutg
        ,awdbuy
        ,awperc
        ,awreas
        ,awfut1
        ,awfut2
        ,awaltf
        ,awftmf
        ,awrecu
        ,awrecc
        ,awpsor
        ,awfuta
        ,awscdt
        ,awdrws
        ,awdrwl
        ,awdenc
        ,awdrel
        ,awddat
        ,awdrws2
        ,awdrwl2
        ,awdenc2
        ,awdrel2
        ,awddat2
        ,awfute
        ,awfutf
        ,awstcl
        ,awvlcd
        ,awsppp
        ,awsppc
        ,awmppp
        ,awmppc
        ,awflg01
        ,awflg02
        ,awflg03
        ,awflg04
        ,awflg05
        ,awflg06
        ,awflg07
        ,awflg08
        ,awflg09
        ,awflg10
        ,awfut01
        ,awfut02
        ,awfut03
        ,awfut04
        ,awfut05
        ,awfut06
        ,awfut07
        ,awfut08
        ,awfut09
        ,awfut10
        ,awfut11
        ,awfut12
        ,awfut13
        ,awfut14
        ,awfut15
        ,awfut16
        ,awfut17
        ,awfut18
        ,awfut19
        ,awfut20
        ,awfut21
        ,awfut22
        ,awfut23
        ,awfut24
        ,awfut25
        ,awfut26
        ,awfut27
        ,awfut28
        ,awfut29
        ,awfut30
        ,awfut31
        ,awfut32
        ,awfut33
        ,awfut34
        ,awfut35
        ,awfut36
        ,awfut37
        ,awfut38
        ,awfut39
        ,awfut40
        ,awfut41
        ,awfut42
        ,awfut43
        ,awfut44
        ,awfut45
        ,awudft
        ,awfrml
        ,awhaza
        ,awlled
        ,awdbac
        ,awscdpt
        ,awfifo
        ,awantid
        ,awsubt
        ,awprcl
        ,awotp
        ,awcbyl
        ,awsrvc
        ,awspal
        ,awpgrp
    FROM
        repl
        INNER JOIN lgdat.stkmp ON
            awpart = repl.clone
    RETURNING *
)
, iicstm AS (
    INSERT INTO lgdat.icstm
    SELECT
        target cgpart
        ,cglabs
        ,cgmats
        ,cgburs
        ,cglaba
        ,cgmata
        ,cgbura
        ,cglabv
        ,cgmatv
        ,cgburv
        ,cgtptd
        ,cgsdat
        ,cgstcs
        ,cgaccs
        ,cgavcs
        ,cgstoc
        ,cgacoc
        ,cgavoc
        ,cgsqty
        ,cgaqty
        ,'C' cgtype
        ,cgbrfs
        ,cgbrvs
        ,cgbrfa
        ,cgbrva
        ,cgbrfv
        ,cgbrvv
        ,cgfuts
        ,cgfuta
        ,cgfutv
        ,cgplnt
        ,cgfut1
        ,cgfut2
        ,cgfut3
        ,cgfut4
        ,cgfut5
        ,cgflg1
        ,cgflg2
        ,cgflg3
    FROM
        repl
        INNER JOIN lgdat.icstm ON
            cgpart = clone
    RETURNING *
)
,iicstp AS (
    INSERT INTO lgdat.icstp
    SELECT
        target chpart
        ,chluc
        ,chlcc
        ,chlfc
        ,chldc
        ,chl1c
        ,chl2c
        ,chsuc
        ,chscc
        ,chsfc
        ,chsdc
        ,chs1c
        ,chs2c
        ,chscr
        ,chlcr
        ,chsdat
        ,chstcs
        ,chaccs
        ,chavcs
        ,chsdr
        ,chs1r
        ,chs2r
        ,chldr
        ,chl1r
        ,chl2r
        ,chsqty
        ,chaqty
        ,'C' chtype
        ,chcurr
        ,chsdwc
        ,chacwc
        ,chplnt
        ,chavuc
        ,chavxc
        ,chavdc
        ,chav1c
        ,chav2c
        ,chavfc
        ,chfut1
        ,chfut2
        ,chfut3
        ,chfut4
        ,chfut5
        ,chflg1
        ,chflg2
        ,chflg3
        ,chflg4
        ,chflg5
        ,chflg6
        ,chflg7
        ,chcrcd
    FROM
        repl
        INNER JOIN lgdat.icstp ON
            chpart = clone
    RETURNING *
)
,iicstr AS (
    INSERT INTO lgdat.icstr
    SELECT
        target y0part
        ,y0plnt
        ,y0stcs
        ,y0accs
        ,y0avcs
        ,y0suc
        ,y0sshr
        ,y0sshc
        ,y0soc
        ,y0sdat
        ,y0sqty
        ,y0luc
        ,y0lshc
        ,y0loc
        ,y0aqty
        ,'C' y0type
        ,y0smat
        ,y0slab
        ,y0svbr
        ,y0sfbr
        ,y0sotc
        ,y0lmat
        ,y0llab
        ,y0lvbr
        ,y0lfbr
        ,y0lotc
        ,y0amat
        ,y0alab
        ,y0avbr
        ,y0afbr
        ,y0aotc
        ,y0aunc
        ,y0ashc
        ,y0acrc
        ,y0fut1
        ,y0fut2
        ,y0fut3
        ,y0fut4
        ,y0fut5
        ,y0flg1
        ,y0flg2
        ,y0flg3
        ,y0crcd
        ,y0stcr
        ,y0lscr
    FROM
        repl
        INNER JOIN lgdat.icstr ON
            clone = y0part
    RETURNING *
)
SELECT 'stka', count(*) FROM istka
UNION ALL
SELECT 'stkmm', count(*) FROM istkmm
UNION ALL
SELECT 'stkmp', count(*) FROM istkmp
UNION ALL
SELECT 'icstm', count(*) FROM iicstm
UNION ALL
SELECT 'icstp', count(*) FROM iicstp
UNION ALL
SELECT 'icstr', count(*) FROM iicstr;