-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi.

It seems there is a bug with SQL CASE support in SQLAlchemy (I'm testing
using trunk).

Here is the original SQL statements:

CREATE TABLE test (
    x INTEGER PRIMARY KEY
);

SELECT
  CASE WHEN 'true'
  THEN (SELECT EXISTS (SELECT x FROM test))
  END;


And here is the Python code:

from sqlalchemy import schema, types, sql, create_engine

metadata = schema.MetaData()
test = schema.Table(
    'test', metadata,
    schema.Column('x', types.Integer, primary_key=True)
    )

engine = create_engine('sqlite://')

subquery = sql.exists(test.select().as_scalar())
clause = sql.case([(True, subquery.select().as_scalar)])
query = clause.select()

engine.execute(query)


I get an error:

Traceback (most recent call last):
  File "case.py", line 13, in <module>
    subquery = sql.exists(test.select().as_scalar())
  File
"/usr/local/lib/python2.5/site-packages/sqlalchemy/sql/expression.py",
line 520, in exists
    return _Exists(*args, **kwargs)
  File
"/usr/local/lib/python2.5/site-packages/sqlalchemy/sql/expression.py",
line 2688, in __init__
    s = select(*args, **kwargs).as_scalar().self_group()
  File
"/usr/local/lib/python2.5/site-packages/sqlalchemy/sql/expression.py",
line 238, in select
    return Select(columns, whereclause=whereclause, from_obj=from_obj,
**kwargs)
  File
"/usr/local/lib/python2.5/site-packages/sqlalchemy/sql/expression.py",
line 3492, in __init__
    if columns:
  File
"/usr/local/lib/python2.5/site-packages/sqlalchemy/sql/expression.py",
line 1289, in __nonzero__
    raise TypeError("Boolean value of this clause is not defined")
TypeError: Boolean value of this clause is not defined


I'm not sure if my code is correct.
If it is not correct, what it the correct method to define that query?



Thanks  Manlio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkth7S4ACgkQscQJ24LbaUQEXgCggBUV3orSFAPPK155cVHplpb4
3U0An1djFkgt3LE6LHQOCHrepVt4F0Vc
=hL1p
-----END PGP SIGNATURE-----

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

Reply via email to