I'm migrating a client's software database from Oracle to PostgreSQL, and I have some trouble understanding a query, what it does, and consequently how to migrate it.
The query is:
SELECT *
FROM TBL1, TBL2, TBL3, TBL4
WHERE TBL3.Project_ID = TBL1.Project_ID
AND TBL2.Type_ID = TBL1.Type_ID
AND TBL4.PROPERTY_NAME(+)='Id'
AND TBL4.Entity_ID(+)=TBL1.Entity_ID
And the part I don't get, is the outer join (+) on 'Id'. A join on a table, OK, but on a string? I've no idea of what it does.
Do someone has an idea? Thanks.
PostgreSQL FULL OUTER JOIN returns all rows from both the participating tables, extended with nulls if they do not have a match on the opposite table. The FULL OUTER JOIN combines the results of both left and right outer joins and returns all (matched or unmatched) rows from the tables on both sides of the join clause.
What is full outer join in Oracle? A full outer join performs a join between two tables that returns the results of an INNER join as well as the results of a left and right outer join. This following query retrieves all rows in the employees table, even if there is no match in the departments table.
AWS DMS migrates your data from your Oracle source into your PostgreSQL target. AWS DMS also captures data manipulation language (DML) and supported data definition language (DDL) changes that happen on your source database and applies these changes to your target database.
The plus sign is Oracle syntax for an outer join. There isn't a minus operator for joins. An outer join means return all rows from one table. Also return the rows from the outer joined where there's a match on the join key. If there's no matching row, return null.
TBL4.PROPERTY_NAME(+)='Id'
means when the line was inner joined, then the value has to be 'Id', but when the line was outer joined, the condition is evaluated as true
however you should rewrite the statement to the standard as:
SELECT *
FROM TBL1
JOIN TBL2 ON TBL2.Type_ID = TBL1.Type_ID
JOIN TBL3 ON TBL3.Project_ID = TBL1.Project_ID
LEFT JOIN TBL4 ON TBL4.Entity_ID=TBL1.Entity_ID AND TBL4.PROPERTY_NAME='Id'
This is the equivalent of the following query using ANSI join syntax:
SELECT *
FROM TBL1 t1
INNER JOIN TBL2 t2 ON (t1.Type_ID = t2.Type_ID)
INNER JOIN TBL3 t3 ON (t3.Project_ID = t1.Project_ID)
LEFT JOIN TBL4 t4 ON (t4.Entity_ID = t1.Entity_ID AND t4.PROPERTY_NAME = 'Id')
You're not joining to a string, merely specifying a join condition that's based on one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With