\encoding UTF8
COPY (SELECT query_to_xml('SELECT tetel.kod as product_id, lang_0000040e as name, 
 replace(replace(replace(trim(iif(fajta1::varchar(255)=''0'' or fajta1=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 1 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = fajta1)='''' ,'''',fajta1::varchar(255))||'' ''||
 iif(fajta2::varchar(255)=''0'' or fajta2=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 2 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = fajta2)='''' ,'''',fajta2::varchar(255))||'' ''||
 iif(fajta3::varchar(255)=''0'' or fajta3=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 3 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = fajta3)='''' ,'''',fajta3::varchar(255))||'' ''||
 iif(fajta4::varchar(255)=''0'' or fajta4=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 4 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = fajta4)='''' ,'''',fajta4::varchar(255))||'' ''||
 iif(fajta5::varchar(255)=''0'' or fajta5=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 5 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = fajta5)='''' ,'''',fajta5::varchar(255))||'' ''||
 iif(fajta6::varchar(255)=''0'' or fajta6=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 6 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = fajta6)='''' ,'''',fajta6::varchar(255))), ''  '', '' ''), ''  '', '' ''), '' '', '','') as categories,
 sor2 as model,
 (SELECT sum(szabad) FROM tetel_raktar WHERE tetel_raktar.tetel_kod = tetel.kod AND tetel_raktar.raktar_kod in (1,13,8,5) ) as quantity,
 (SELECT nev FROM partner WHERE partner.kod = tetel.jellemzo_beszallito) as manufacturer,
 (SELECT egysegar FROM tetel_egysegar WHERE tetel_egysegar.tetel_kod = tetel.kod AND egysegar_kod = 101) as price_listaar,
 egy_egyseg_sulya as weight,
 ''kg'' as weight_unit,
 tetel.afa_kulcs as tax_class_id,
 (SELECT afakulcs FROM afa_kulcs WHERE afa_kulcs.kod = tetel.afa_kulcs) as tax_value,
 akcios as on_sale,
 iif(hasznalatban=-1,1,0) as is_parent,
 tetel_kapcsolat_szulo as parent_id,
 '''' as parent_param,
 szoveges_kod, vonalkod as barcode,
 min_ert_egyseg as min,
 pontertek as special_offer,
 iif(hasznalatban>0  AND webboltban = 1, 0,1) as deleted
 FROM tetel
 WHERE ((tetel.lasteditedtime_forsync + interval ''12 hours'') > current_timestamp)
UNION
SELECT t_sz.kod as product_id, t_sz.lang_0000040e as name, 
 replace(replace(replace(trim(iif(t_gy.fajta1::varchar(255)=''0'' or t_gy.fajta1=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 1 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = t_gy.fajta1)='''' ,'''',t_gy.fajta1::varchar(255))||'' ''||
 iif(t_gy.fajta2::varchar(255)=''0'' or t_gy.fajta2=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 2 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = t_gy.fajta2)='''' ,'''',t_gy.fajta2::varchar(255))||'' ''||
 iif(t_gy.fajta3::varchar(255)=''0'' or t_gy.fajta3=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 3 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = t_gy.fajta3)='''' ,'''',t_gy.fajta3::varchar(255))||'' ''||
 iif(t_gy.fajta4::varchar(255)=''0'' or t_gy.fajta4=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 4 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = t_gy.fajta4)='''' ,'''',t_gy.fajta4::varchar(255))||'' ''||
 iif(t_gy.fajta5::varchar(255)=''0'' or t_gy.fajta5=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 5 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = t_gy.fajta5)='''' ,'''',t_gy.fajta5::varchar(255))||'' ''||
 iif(t_gy.fajta6::varchar(255)=''0'' or t_gy.fajta6=(SELECT kod FROM tetel_fajtak WHERE fajta_kod = 6 AND ures = 1) or (SELECT webboltban_nev FROM tetel_fajtak WHERE kod = t_gy.fajta6)='''' ,'''',t_gy.fajta6::varchar(255))), ''  '', '' ''), ''  '', '' ''), '' '', '','') as categories,
 t_sz.sor2 as model,
 0 as quantity,
 (SELECT nev FROM partner WHERE partner.kod = t_gy.jellemzo_beszallito) as manufacturer,
 0 as price_listaar,
 0 as weight,
 ''kg'' as weight_unit,
 t_gy.afa_kulcs as tax_class_id,
 (SELECT afakulcs FROM afa_kulcs WHERE afa_kulcs.kod = t_gy.afa_kulcs) as tax_value,
 0 as on_sale,
 1 as is_parent,
 0 as parent_id,
 t_sz.sor3 as parent_param,
 t_sz.szoveges_kod, t_sz.vonalkod as barcode,
 t_sz.min_ert_egyseg as min,
 t_gy.pontertek as special_offer,
 iif(t_sz.hasznalatban=-1,0,1) as deleted
 FROM tetel t_sz
 LEFT JOIN tetel t_gy ON t_gy.tetel_kapcsolat_szulo = t_sz.kod AND t_gy.hasznalatban > 0 AND t_gy.webboltban = 1
 WHERE (not(t_gy.kod is null))
  AND ((t_sz.lasteditedtime_forsync + interval ''12 hours'') > current_timestamp)
', true, false, '')) to '/tmp/flexovit_tetel_changed.xml'
