SQLProvider icon indicating copy to clipboard operation
SQLProvider copied to clipboard

Oracle: outer join retrieves no result

Open object opened this issue 8 years ago • 10 comments

When using query with outer join syntax (operator !!) no results are retrieved in case the joined table has no matching rows, so outer join works as inner join.

Example:

query { for p in dbContext.Granitt.Programmes do
        join d in (!!) dbContext.Granitt.ProgrammesDistributions on (p.ProgrammeId = d.ProgrammeId)
        where (p.PiProgId = "KOID35004614") 
        select p.PiProgId }

dbContext.Granitt.Programmes has a record with PiProgId "KOID35004614", so if remove a join on dbContext.Granitt.ProgrammesDistributions, I get back correct result. But if I join two tables on ProgrammeId (primary key on Programmes and foreign key on ProgrammesDistributions), then I get no results.

The database is Oracle.

Here's a generated query:

Executing SQL: SELECT p.PI_PROG_ID as "p.PI_PROG_ID",p.PROGRAMME_ID as "p.PROGRAMME_ID",d.PROGRAMME_DISTRIBUTION_ID as "d.PROGRAMME_DISTRIBUTION_ID" FROM GRANITT.PROGRAMMES p INNER JOIN GRANITT.PROGRAMMES_DISTRIBUTIONS d on p.PROGRAMME_ID = d.PROGRAMME_ID WHERE ((p.PI_PROG_ID = :param1)) - params :param1 - "KOID35004614";

As you can see, it's an INNER JOIN in the SQL statement.

object avatar Oct 25 '16 08:10 object

It might be useful in this case if we can have a look at what SQL it is generating, you can use FSharp.Data.Sql.Common.QueryEvents.SqlQueryEvent |> Event.add (printfn "Executing SQL: %s") to listen in to what is being submitted to the database.

pezipink avatar Oct 25 '16 10:10 pezipink

I have updated the issue with generated SQL statement. It's an inner join that is generated.

object avatar Oct 25 '16 12:10 object

Sorry, I totally forgot about this. The Oracle code seems to be dealing with left joins appropriately, but I don't have an Oracle system to test it with. @colinbull ?

pezipink avatar Dec 14 '16 11:12 pezipink

If you need to verify the fix, I have access to an Oracle system.

object avatar Dec 16 '16 08:12 object

I can have a look at this but unlikely to get to it until next week. So if someone can verify / fix sooner that be awesome.

colinbull avatar Dec 16 '16 12:12 colinbull

Just let me know when there is a commit I can check.

object avatar Dec 19 '16 08:12 object

@colinbull did this get fixed in the end? I remember we (you) were looking at it at F#ex ..

pezipink avatar Apr 19 '17 14:04 pezipink

@pezi_pink no I do know what is wrong thou.. it is todo with the resolution of the outerjoin pattern not matching correctly probably needs to match on 'op_BangBang' or something like that.

colinbull avatar Apr 19 '17 16:04 colinbull

Any love for this issue? Working without left join is difficult.

OnurGumus avatar Nov 14 '18 03:11 OnurGumus

This is working now!

OnurGumus avatar Jan 15 '19 18:01 OnurGumus