I'm doing conversation from mysql to postgres.
I try to update table EUTMPDFHDT T with join table EUTMPDFH T1 and EUTMPTBLDT T2.
Here is code what I use in mysql.
UPDATE EUTMPDFHDT
SET NWCOLID=T2.NWCOLID
FROM EUTMPDFHDT T
INNER JOIN EUTMPDFH T1 ON T.DFHID = T1.DFHID AND T1.DFHTYP IN ('D','U','S','P','B')
INNER JOIN EUTMPTBLDT T2 ON T.COLID = T2.COLID
In postgres I did try to follow this UPDATE statement with multiple joins in PostgreSQL
But to no avail I cannot solve it because the update statement is not same.
Here what have I done in postgres:
UPDATE EUTMPDFHDT AS T
SET NWCOLID=T2.NWCOLID
FROM
EUTMPDFH T1
JOIN EUTMPTBLDT T2 ON T.COLID = T2.COLID
WHERE T.DFHID = T1.DFHID AND T1.DFHTYP IN ('D','U','S','P','B');
Here is the error that I hit
ERROR: invalid reference to FROM-clause entry for table "t"
LINE 5: JOIN EUTMPTBLDT T2 ON T.COLID = T2.COLID
^
HINT: There is an entry for table "t", but it cannot be referenced from this part of the query.
QUERY: UPDATE EUTMPDFHDT AS T
SET NWCOLID=T2.NWCOLID
FROM
EUTMPDFH T1
JOIN EUTMPTBLDT T2 ON T.COLID = T2.COLID
WHERE T.DFHID = T1.DFHID AND T1.DFHTYP IN ('D','U','S','P','B')