Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle's OUTER JOIN (+) on string - Migration PostgreSQL

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.

like image 926
Tiller Avatar asked Apr 29 '15 09:04

Tiller


People also ask

Does PostgreSQL support outer join?

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.

Does Oracle support full outer join?

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.

Can Oracle be migrated to PostgreSQL?

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.

What is (+) in Oracle join?

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.


2 Answers

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' 
like image 83
Pavel Gatnar Avatar answered Oct 23 '22 02:10

Pavel Gatnar


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.

like image 32
ninesided Avatar answered Oct 23 '22 03:10

ninesided