0

I am trying to convert below Sybase query into sqlAlchemy code but getting different result.


select distict A.ip, isnull(HH.hn,'-')
from 
DS d,
IN I,
DHC A,
DBI H,
DBI HH,
DBI H2,
where
S.id = I.id and
A.ip = I.ip and
A.ip = H.ip and
HH.df=0 and
A.ip *= HH.ip and
A.ip = H2.ip and
H2.hn ='abc' 
order by A.ip, HH.hn;

I have models defined for DS,IN,DHC,DBI and used below ORM query.

# created aliased for S,I A,H,HH,H2
db_session(S,I,A,H,HH,H2)\
.with_entities(A.ip, HH.hn)\
.filter(S.id == I.id,
        A.ip == I.ip,
        A.ip == H.ip,
        HH.df=0,
        A.ip == H2.ip,
        H2.hn= 'abc')
.join(HH, A.ip == HH.ip, isouter = True)\
.order_by(A.ip, HH.hn)
.distinct().all()

Original query returns Null on the HH.hn but no nulls for HH.hn with ORM. What am I missing here?

tempuser
  • 1,517
  • 3
  • 11
  • 15

0 Answers0