Multiple Selects

14 views
Skip to first unread message

Stephen Greenfield

unread,
Apr 29, 2016, 4:10:03 AM4/29/16
to python-sql
I've read over https://pypi.python.org/pypi/python-sql and I have a question.

Is it possible to add to a select at different points in code? I'm looking to have a base method GetBaseBuilder() that returns an object, and then other methods call it and add various joins and selects depending. Is this possible with python-sql?

Thanks!
Stephen

Nicolas Évrard

unread,
Apr 29, 2016, 4:46:08 AM4/29/16
to python-sql
* Stephen Greenfield [2016-04-29 05:27 +0200]:
I am not sure to understand what you mean but you could definitely do
something like this:


def GetBaseBuilder():
table_a = Table('a')
table_b = Table('b')

return table_a.join(table_b, condition=table_a.id == table_b.a)

And somewhere else in the code:

base = GetBaseBuilder()
base.join(table_c, condition=…).select(…)

But if you want to make a reference to the tables used in the
GetBaseBuilder, you should either use the _left and _right properties
of the join or return them from the GetBaseBuilder call.

Hope it helps.

--
Nicolas Évrard - B2CK SPRL
E-mail/Jabber: nicolas...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
Reply all
Reply to author
Forward
0 new messages