\encoding UTF8
COPY (SELECT query_to_xml('SELECT kod as customer_id, nev as name,
  cim as address_1,
  iszam as postcode,
  telepules as city,
  orszag as country,
  0 as address_type,
  county.cty_name as county,
  county.flx_webshop_zone_id as zone_id,
  city.cit_lat as latitude,
  city.cit_long as longitude
  FROM partner
  LEFT JOIN wsh_co_city city ON city.cit_zip = partner.iszam
  LEFT JOIN wsh_co_county county ON county.cty_code = city.cit_cty_code
  WHERE (not(webbolt_userid = '''')) and (not(webbolt_userid = ''-'')) and (not(webbolt_userid is null))
 UNION
  SELECT partner_kod as customer_id, nev as name,
  cim as address_1,
  iszam as postcode,
  telepules as city,
  orszag as country,
  cim_tipus as address_type,  
  county.cty_name as county,
  county.flx_webshop_zone_id as zone_id,
  city.cit_lat as latitude,
  city.cit_long as longitude
  FROM partner_cimtar
  LEFT JOIN wsh_co_city city ON city.cit_zip = partner_cimtar.iszam
  LEFT JOIN wsh_co_county county ON county.cty_code = city.cit_cty_code
  WHERE (not((SELECT webbolt_userid FROM partner WHERE partner.kod = partner_cimtar.partner_kod) = ''''))
    AND (not((SELECT webbolt_userid FROM partner WHERE partner.kod = partner_cimtar.partner_kod) = ''-''))
    AND (not((SELECT webbolt_userid FROM partner WHERE partner.kod = partner_cimtar.partner_kod) is null))
 order by 1,7', true, false, '')) to '/tmp/flexovit_partner-cim.xml'