I made a bit of progress, as I couldn't get the orm version to work I
tried creating it using select.
I used aliases and made two separate selects to better be able to debug
things.
a1 = db.Somecode_T.__table__.alias('a1')
a2 = db.Somecode_T.__table__.alias('a2')
sa = db.sa.select([a2.c.id], db.sa.and_(a2.c.code_id == a1.c.code_id,
a2.c.lang_code5 == 'FR_fr'))
s = db.sa.select([a1], db.sa.or_(a1.c.lang_code5 == 'FR_fr',
db.sa.and_(a1.c.lang_code5 == 'EN_en',
db.sa.not_(db.sa.exists(sa)))))
This gives the result I am looking for, so then I went back to the orm
version which I still can't get to work.
stAlias1 = db.sao.aliased(db.Somecode_T)
stAlias2 = db.sao.aliased(db.Somecode_T)
sa = session.query(stAlias2.id).filter(db.sa.and_(stAlias2.code_id ==
stAlias1.code_id,
stAlias2.lang_code5
== 'FR_fr'))
s1 = session.query(stAlias1).filter(db.sa.or_(stAlias1.lang_code5 ==
'FR_fr',
db.sa.and_(stAlias1.lang_code5 == 'EN_en',
db.sa.not_(db.sa.exists(sa)))))
The above gives me the following exception:
c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\sql\expression.py:2901:
SAWarning: Column '(4,)' on table 'Select object' being replaced by
another column with the same key. Consider use_labels for select()
statements.
selectable.columns[c.name] = c
c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\sql\expression.py:2901:
SAWarning: Column '(6,)' on table 'Select object' being replaced by
another column with the same key. Consider use_labels for select()
statements.
selectable.columns[c.name] = c
Traceback (most recent call last):
File "saTest.py", line 116, in <module>
db.sa.not_(db.sa.exists(sa)))))
File
"c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\sql\expression.py",
line 515, in exists
return _Exists(*args, **kwargs)
File
"c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\sql\expression.py",
line 2466, in __init__
s = select(*args, **kwargs).as_scalar().self_group()
File
"c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\sql\expression.py",
line 3014, in as_scalar
return _ScalarSelect(self)
File
"c:\python25\lib\site-packages\sqlalchemy-0.5.8-py2.5.egg\sqlalchemy\sql\expression.py",
line 3117, in __init__
raise exc.InvalidRequestError("Scalar select can only be created "
sqlalchemy.exc.InvalidRequestError: Scalar select can only be created
from a Select object that has exactly one column expression.
Can a kind soul point me in the right direction.
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.