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)
            restwave = wave/(1+redshift)
            return restwave
        else:
            return None

    @restwave.expression
    def restwave(cls): 
        session = db.Session()
        nsaz = session.query(sampledb.NSA.z.label('z')).\
            join(sampledb.MangaTargetToNSA, sampledb.MangaTarget, Cube).\
            filter(Cube.mangaid == cls.mangaid).subquery('nsaz', with_labels
=True)
        unwave = session.query((func.unnest(Wavelength.wavelength)/(1+nsaz.c
.z)).label('restw')).subquery('unwave', with_labels=True)
        restwave = session.query(func.array_agg(unwave.c.restw)).as_scalar()


        return restwave 

Using the example query, 
rwquery = 
session.query(datadb.Cube.restwave).filter(datadb.Cube.mangaid=='1-113520')


-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to