Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-04 Thread Brian Cherinka
> > > > I've yet to see an unambiguous statement of what "the raw SQL" is. If > it is this: > > select c.pk,c.mangaid,c.manga_target_pk, n.z, > (select (array_agg(unwave.restw))[0:5] as restwave from (select > (unnest(w.wavelength)/(1+n.z)) as restw from mangadatadb.wavelength as > w) as

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-04 Thread Mike Bayer
On 08/04/2016 12:03 PM, Brian Cherinka wrote: Yeah, sorry about that. Like I said, I don't normally build my classes this way, defining all the columns in the Base Class. I define all my columns, primary and foreign keys, etc manually first, so my SQLA classes are minimally defined. And I

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-04 Thread Brian Cherinka
Yeah, sorry about that. Like I said, I don't normally build my classes this way, defining all the columns in the Base Class. I define all my columns, primary and foreign keys, etc manually first, so my SQLA classes are minimally defined. And I cobbled together pieces from my real code and

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-03 Thread Mike Bayer
There is still much ambiguity here and inaccuracy (JOINs on the outside or JOINs on the inside, the mappings have mistakes like foreign key to "pk" but no "pk", mappings without primary keys, "autoload" makes no sense as I don't have your tables, etc.), so I can only guess but perhaps give you

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-03 Thread Brian Cherinka
Ok. Yeah, I have been trying many different ways of getting results. The raw SQL that I'm trying to recreate in SQLA is this (for the restwave column only), which works in postgresql. The limit was only there to do the filter the results. You can ignore that limit. manga=# select

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-03 Thread Mike Bayer
OK first problem is, the SQL you showed me is: select ( select (array_agg(unwave.restw)) as restwarr from ( select ( unnest(w.wavelength)/(1+n.z)) as restw from mangadatadb.wavelength as w ) as unwave ) from mangadatadb.cube as c join

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-03 Thread Brian Cherinka
Ok. Here is my test file. I tried to set it up as much as I could, but I don't normally set up my db and sessions this way, so you may have to hack a bit here and there to finish some setup. My original setup has classes from two different schema. I don't know if that makes any difference.

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-03 Thread Brian Cherinka
Awesome. Thanks. Ok. I'll work on it again, and get back to you as soon as I can. On Tuesday, August 2, 2016 at 3:57:10 PM UTC-4, Mike Bayer wrote: > > What I need is a complete .py file that sets up a *minimal* version of > *every* class required, then the Query object, then prints it.

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-02 Thread Mike Bayer
What I need is a complete .py file that sets up a *minimal* version of *every* class required, then the Query object, then prints it. I'll mangle it to do the right thing. Like this: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-02 Thread Brian Cherinka
So I managed to get something to return using this definition of the @expression, however, I'm not quite there yet. @hybrid_property def restwave(self): if self.target: redshift = self.target.NSA_objects[0].z wave = np.array(self.wavelength.wavelength)

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-08-02 Thread Brian Cherinka
So I managed to get something to return using this definition of the @expression, however, I'm not quite there yet. @hybrid_property def restwave(self): if self.target: redshift = self.target.NSA_objects[0].z wave = np.array(self.wavelength.wavelength)

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-07-29 Thread Brian Cherinka
The @expression as column thing is a bit confusing since in the correlated subquery example in the hybrid attribute section, it looks like you are returning a select? Does the .label() effectively turn it into a column? class User(Base): __tablename__ = 'user' id = Column(Integer,

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-07-29 Thread Brian Cherinka
Oh interesting. I didn't know that about the @expression. I'll play around with the as_scalar() as well, and see if I can get something to work. class Wavelength(Base): __tablename__ = 'wavelength' __table_args__ = {'autoload': True, 'schema': 'mangadatadb', 'extend_existing':

Re: [sqlalchemy] nested subqueries in a hybrid expression?

2016-07-29 Thread Mike Bayer
you might need to change more than this, but at least the fundamental thing about @expression is that it has to return a column, not a Query or a select(). On either one, calling as_scalar() will give you a scalar subquery, e.g. a SELECT interpreted as a column. Assuming there's still