full outer join?

672 views
Skip to first unread message

Chris Withers

unread,
Dec 1, 2013, 5:08:49 PM12/1/13
to sqlal...@googlegroups.com
This feels like a newbie question, but how would I do a full outer join
in SQLAlchemy?

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

Michael Bayer

unread,
Dec 1, 2013, 5:20:25 PM12/1/13
to sqlal...@googlegroups.com
I have a similar question - why ?
> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
> To post to this group, send email to sqlal...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.

signature.asc

Chris Withers

unread,
Dec 2, 2013, 2:05:46 PM12/2/13
to sqlal...@googlegroups.com
I have a self join (same one I've been asking about recently) and turns
out that there should be a one to one mapping for the aggregated rows on
one side to the aggregated rows on the other side.

If that's not true, then the returned rows are rubbish. In all my
current use cases it *should* be true but I'm looking for a join that
will show me when something has changed by having nulls in either the
left or right side of the join.

If you can suggest a way that doesn't involve a full outer join, I'm all
ears :-)

Michael Bayer

unread,
Dec 2, 2013, 2:46:20 PM12/2/13
to sqlal...@googlegroups.com
well the alternative to full outer join is a union of two outer joins - more tedious. “full outer join” isn’t in the library but you can just subclass Join and do a @compiles to get that exact syntax.
signature.asc

Jonathan Vanasco

unread,
Dec 2, 2013, 5:43:11 PM12/2/13
to sqlal...@googlegroups.com


On Monday, December 2, 2013 2:46:20 PM UTC-5, Michael Bayer wrote:
well the alternative to full outer join is a union of two outer joins - more tedious.    “full outer join” isn’t in the library but you can just subclass Join and do a  @compiles to get that exact syntax.

you could also query the union of two outer joins, by treating it as a nested subquery.  that is not only tedious, but painful and annoying.   you could do it though!

Michael Bayer

unread,
Dec 2, 2013, 8:09:14 PM12/2/13
to sqlal...@googlegroups.com
if someone wants to pullreq the kw argument “full=True” on .outerjoin(), if it’s done effectively I won’t reject it.


signature.asc

Stefan Urbanek

unread,
Apr 17, 2015, 3:24:55 PM4/17/15
to sqlal...@googlegroups.com
I've added a PR for full=True in outerjoin(), join() and Join():

    https://github.com/zzzeek/sqlalchemy/pull/167

FULL OUTER JOIN, besides other uses, is very useful in ETLs for doing transformations on top of table differences. Using two outer joins, as suggested in one of the above posts, unnecessarily overcomplicates statements.

Stefan
Reply all
Reply to author
Forward
0 new messages