Re: [openstack-dev] [Neutron] need help in translating sql query to sqlalchemy query

2015-12-02 Thread Sean M. Collins
Was perusing the documentation again this morning and there is another thing I found - you can call join() with the aliased=True flag to get similar results. Check out the "Constructing Aliases Anonymously" section. http://docs.sqlalchemy.org/en/latest/orm/query.html -- Sean M. Collins

Re: [openstack-dev] [Neutron] need help in translating sql query to sqlalchemy query

2015-12-01 Thread Venkata Anil
Thanks Sean. I will check that. Meanwhile I tried this and it is working port1 = orm.aliased(models_v2.Port, name="port1") port2 = orm.aliased(models_v2.Port, name="port2") router_intf_qry = context.session.query(RouterPort.router_id).join((port1,

Re: [openstack-dev] [Neutron] need help in translating sql query to sqlalchemy query

2015-12-01 Thread Sean M. Collins
On Tue, Dec 01, 2015 at 10:22:41AM EST, Venkata Anil wrote: > Thanks Sean. I will check that. > > Meanwhile I tried this and it is working > > port1 = orm.aliased(models_v2.Port, name="port1") > port2 = orm.aliased(models_v2.Port, name="port2") > router_intf_qry = >

Re: [openstack-dev] [Neutron] need help in translating sql query to sqlalchemy query

2015-12-01 Thread Venkata Anil
On 12/01/2015 09:06 PM, Sean M. Collins wrote: On Tue, Dec 01, 2015 at 10:22:41AM EST, Venkata Anil wrote: Thanks Sean. I will check that. Meanwhile I tried this and it is working port1 = orm.aliased(models_v2.Port, name="port1") port2 = orm.aliased(models_v2.Port,

[openstack-dev] [Neutron] need help in translating sql query to sqlalchemy query

2015-12-01 Thread Venkata Anil
Hi All I have the below sql query which - "lists routers connected to given internal and external networks" select DISTINCT routerports.router_id from routerports inner join ports as ports1 on (ports1.id=routerports.port_id and ports1.network_id=internal_network_id) inner join ports as

Re: [openstack-dev] [Neutron] need help in translating sql query to sqlalchemy query

2015-12-01 Thread Sean M. Collins
Consult the API: http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.join In fact, there is already one join happening a couple lines above your change: https://github.com/openstack/neutron/blob/stable/liberty/neutron/db/l3_db.py#L800 Most likely, you will also need