5

I know there is a WHERE representation of LEFT JOIN in Oracle that has syntax like:

  FROM t1, t2
 WHERE t1.id = t2.id(+)

instead of:

  FROM t1 LEFT JOIN t2
    ON t1.id = t2.id

Is there anything similar in PostgreSQL? I searched for documentation, but failed to find such feature.

4

1 Answer 1

11

There is no such operator in Postgres (or standard SQL).

The only way to write an outer join in Postgres is to use an ANSI explicit JOIN syntax:

select *
from table t1
  left join table t2 on t1.id = t2.id;

(or it might be the other way round - it has been ages since I last used the Oracle (+) operator)

More details in the manual: http://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-FROM

You shouldn't be using the (+) operator in Oracle in the first place. Oracle has supported ANSI joins since 9i and Oracle recommends stop using the (+) operator (the above statement will work just fine in Oracle as well)

Sign up to request clarification or add additional context in comments.

5 Comments

As i understand, there is no "Oracle (+)" like equivalent in PostgreSQL?
@DraggonZ No, there isn't. Why do you want that? To not have to rewrite the Oracle query?
@Clodoaldo Neto To not to rewrite much existing PostgreSQL query. That query dynamically builds from C# code (something like whereString += tableName + ".id = " + table.Table + "." + tableName + "_id AND ";) It's a legacy code without tests, and I need to replace some wheres with left joins without breaking any other logic.
@DraggonZ: no there is no such operator in Postgres - and you shouldn't be using it in Oracle either.
@a_horse_with_no_name Could you move this to your answer? I'll accept it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.