On 28/01/2010 11:05, werner wrote:
I have one more variation on my translation stuff.

Trying to translate this sql:

select *
from MyTable M1
where
  M1.LANG_CODE5 = 'FR_fr'
  or (
    M1.LANG_CODE5 = 'EN_en'
    AND NOT EXISTS(
SELECT 1 FROM MyTable M2 where M2.CODE_ID = M1.CODE_ID and M2.LANG_CODE5 = 'FR_fr'
    )
  )


to SA, I can't figure out how to represent "select 1 from mytable".

May I ask again for some tips on this.

Forgot to include what I have so far:

s1 = session.query(db.Somecode_T).filter(db.sa.or_(db.Somecode_T.lang_code5 == 'FR_fr', db.sa.and_(db.Somecode_T.lang_code5 == 'EN_en',
                                            db.sa.not_(db.sa.exists(
                    session.query(stAlias1).filter(db.sa.and_(
db.Somecode_T.code_id == stAlias1.code_id, stAlias1.lang_code5 == 'FR_fr')))))))

But the "limit(1) isn't what is needed :-[ .

So, I tried this:

s1 = session.query(db.Somecode_T).filter(db.sa.or_(db.Somecode_T.lang_code5 == 'FR_fr', db.sa.and_(db.Somecode_T.lang_code5 == 'EN_en',
                                            db.sa.not_(db.sa.exists(
                    session.query(stAlias1.id).filter(db.sa.and_(
db.Somecode_T.code_id == stAlias1.code_id, stAlias1.lang_code5 == 'FR_fr')))))))

But here I get an exception:
"sqlalchemy.exc.InvalidRequestError: Scalar select can only be created from a Select object that has exactly one column expression."

Werner
Werner

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to