I want to migrate an oracle query to postgresql :
here is the oracle version :
SELECT
replace(replace(replace(
cf.NO_FACTURE||';'||
cf.MODULE||';'||
replace(replace(replace(cf.REF_FACTURE_SYBEL,'&',' '),'''',''''''),';','')||';'||
nvl(replace(to_char(cf.SOLDE_VERSE),',','.'),0)||';'||
cf.DATE_PAIEMENT_FACTURE||';'||
nvl(replace(to_char(cf.MONTANT_ACOMPTE_VERSE),',','.'),0)
, CHR(10),''),CHR(13),''),'*',' ')
FROM
(SELECT distinct td_inf.NO_FACTURE
FROM tac_dossier td_inf,
com_agent ca,
com_habilitation ch
WHERE td_inf.etat_dossier = 'id.15.ClosFacturation'
AND MONTHS_BETWEEN(sysdate,td_inf.date_chgt_etat) > $nb_mois_clos
AND td_inf.cod_ag_resp = ca.cod_ag(+)
AND ch.cod_ag = ca.cod_ag
AND ch.cod_ent in (select cod_ent from com_ent_ft where pole = td_inf.cod_ent or cod_ent = td_inf.cod_ent)) td,
COM_FACTURE cf
WHERE cf.NO_FACTURE = td.NO_FACTURE;
and here is my postgresql version of the query :
SELECT
replace(replace(replace(
cf.NO_FACTURE||';'||
cf.MODULE||';'||
replace(replace(replace(cf.REF_FACTURE_SYBEL,'&',' '),'''',''''''),';','')||';'||
COALESCE(replace(to_char(cf.SOLDE_VERSE),',','.'),'0')||';'||
cf.DATE_PAIEMENT_FACTURE||';'||
COALESCE(replace(to_char(cf.MONTANT_ACOMPTE_VERSE),',','.'),'0')
, CHR(10),''),CHR(13),''),'*',' ')
FROM
(SELECT distinct td_inf.NO_FACTURE
FROM
tac_dossier td_inf
LEFT OUTER JOIN com_agent ca ON td_inf.cod_ag_resp = ca.cod_ag
INNER JOIN com_ent_ft cef ON (cef.pole = td_inf.cod_ent or cef.cod_ent = td_inf.cod_ent)
INNER JOIN com_habilitation ch ON (ch.cod_ag = ca.cod_ag and ch.cod_ent = cef.cod_ent)
WHERE td_inf.etat_dossier = 'id.15.ClosFacturation'
AND EXTRACT(month from age(NOW(),td_inf.date_chgt_etat)) > 2
) td,
COM_FACTURE cf
WHERE cf.NO_FACTURE = td.NO_FACTURE;
The query is working there is no problem in the syntax But the results of the two queries are different.
Any note on this ?
Thank you.