sql >> Database >  >> RDS >> PostgreSQL

Moet Oracle merge omzetten in query naar PostgreSQL

U kunt INSERT ON CONFLICT () . gebruiken in plaats daarvan:

insert into feepay.TRPT_W2_REPORTS (ACCOUNT, URN, LAST_NAME, FIRST_NAME, ISENTITY, DOB, ADDRESS, LAST_UPDATE, STATUS)
WITH RWS AS (
  SELECT PROG.BINCLIENT, TRPT.PUT_DIRECTORY
  FROM  feepay.program2 PROG
    INNER JOIN  feepay.TRPT_W2_PROGRAMS TRPT
            ON (PROG.BINCLIENT = TRPT.BINCLIENT OR PROG.ISSUER_ID = TRPT.ISSUER_ID)
)
SELECT TCI.CUSTOMERNAME,
       TC.CUSTOMER_ID,
       TC.LAST_NAME,
       TC.FIRST_NAME,
       'Y'
       TC.DOB,
       TCA.ADDRESS, 
       now(), 
       'i'
FROM feepay.TAU_CARDNUMBERS TCN
  INNER JOIN feepay.TAU_CUSTOMER_CARDNUMBER TCCN ON (TCN.CARDNUMBER_ID = TCCN.CARDNUMBER_ID)
  INNER JOIN feepay.TBLCUSTOMERS TC ON (TCCN.CUSTOMER_ID = TC.CUSTOMER_ID)
  LEFT JOIN feepay.tau_customeraddress TCA ON (TC.CUSTOMER_ID = TCA.CUSTOMER_ID)
  INNER JOIN feepay.TAU_ISSUER TI ON (TI.ISSUER_ID = TCN.ISSUER_ID)
  INNER JOIN feepay.TBLCUSTOMERS TCI ON (TCI.CUSTOMER_ID = TI.CUSTOMER_ID)
  LEFT JOIN feepay.TRPT_W2_REPORTS TRPT ON (TRPT.URN = TC.CUSTOMER_ID)
WHERE BINCLIENT IN (SELECT BINCLIENT FROM RWS)
  AND TC.CUSTOMERNAME NOT IN ('freepay card','svds card')) TRPT2
ON CONFLICT (URN)
DO UPDATE SET
  ACCOUNT = excluded.ACCOUNT,
  LAST_NAME = excluded.LAST_NAME,
  FIRST_NAME = excluded.FIRST_NAME,
  DOB = excluded.DOB,
  ADDRESS = excluded.ADDRESS,
  LAST_UPDATE = now(),
  STATUS = 'u' /* uPDATED */

U moet controleren of de kolommen in de SELECT-lijst overeenkomen met de kolommen zoals vermeld in de INSERT-kolomlijst.




  1. Vernieuwen van SQL Server-tabellen met minder onderbrekingen met behulp van Partition Switching

  2. Hoe u de maand van een datum haalt in MySQL

  3. Getallen opmaken met komma's in PostgreSQL

  4. Intel SSD, nu van de sh..err, beschaamde lijst