for this sql script in postgresl:

CREATE TEMP table temp_coupons AS

SELECT sd.id AS idsegmentname,

    sd.forpnrhandlingid AS idbooking,

    si.id AS iditinerary,

    sd.segmentname AS type,

    scf.cpnnumber AS coupon_number,

    scf.cpnsequencenumber AS sequence_number,

    sf2.datefile

   FROM sbr_dataelementsstruct sd

     JOIN sbr_fa sf ON sd.id = sf.dataelementsstructid

     JOIN sbr_couponsinfo_fa scf ON sf.id = scf.faid

     JOIN sbr_itineraryinfo si ON sd.forpnrhandlingid = si.forpnrhandlingid AND scf.cpnsequencenumber = si.elementmanagement_number

join sbr_forpnrhandling sf2

on sd.forpnrhandlingid = sf2.id where date_trunc('Day',sf2.datefile) between '2023-01-01' and '2023-01-07' and sf2.isactive = 'Y' and sf2.islast = 'Y';

    

create temp table temp_post as

SELECT sd.id AS idpdl,

    NAME_1(sd.forpnrhandlingid) AS idbooking,

    NAME_1(sd.paxstatus_indicator2::text) AS boarded_indicator,

    NAME_1(

        CASE

            WHEN st2.id IS NOT NULL THEN st2.id

            ELSE NULL::bigint

        END) AS idpassenger,

    NAME_1(

        CASE

            WHEN si.id IS NOT NULL THEN si.id

            ELSE NULL::bigint

        END) AS iditinerary

   FROM sbr_dataelementsstruct sd

JOIN sbr_reference_dataelementsstruct srd2 ON sd.id = srd2.dataelementsstructid

LEFT JOIN sbr_travellerinfo st2 ON sd.forpnrhandlingid = st2.forpnrhandlingid AND 'PT'::text = st2.qualifier::text AND srd2.reference_qualifier::text = 'PT'::text AND st2.number::character varying(5)::text = srd2.reference_number::text

LEFT JOIN sbr_itineraryinfo si ON sd.forpnrhandlingid = si.forpnrhandlingid AND 'ST'::text = si.elementmanagement_qualifier::text AND srd2.reference_qualifier::text = 'ST'::text AND si.elementmanagement_number::character varying(5)::text = srd2.reference_number::text

join sbr_forpnrhandling sf2

on sd.forpnrhandlingid = sf2.id where date_trunc('Day',sf2.datefile) between '2023-01-01' and '2023-01-07' and sf2.isactive = 'Y' and sf2.islast = 'Y'

and sd.segmentname::text = 'PDL'::text

GROUP BY sd.id;

 

create temp table temp_tickets as

SELECT sf.id AS idticket,

    sf.dataelementsstructid AS idsegmentname,

    sd.forpnrhandlingid AS idbooking,

    st.pricetarifftype AS tarifftype_indicator,

    sd.segmentname AS type,

    sf.othercompany::text || sf.documentdetails_number AS ticket_number,

    sf.numberofbooklets AS conjunctive_booklet,

    sf.status,

    (lpad(sf.day::character varying(2)::text, 2, '0'::text) || lpad(sf.month::character varying(2)::text, 2, '0'::text)) || "substring"(sf.y