2 messages in com.googlegroups.sqlalchemy[sqlalchemy] problems with exists
FromSent OnAttachments
Manlio Perillo23 Feb 2007 07:25 
Michael Bayer23 Feb 2007 10:44 
Subject:[sqlalchemy] problems with exists
From:Manlio Perillo (manl@gmail.com)
Date:02/23/2007 07:25:15 AM
List:com.googlegroups.sqlalchemy

Hi.

I'm having problems with the exists clause.

Here is the code:

from sqlalchemy import *

db = create_engine('sqlite:///', echo=True) metadata = BoundMetaData(db)

test = Table( 'test', metadata, Column('id', Integer, primary_key=True), Column('x', String), Column('y', String) )

metadata.create_all() try: conn = db.contextual_connect()

# i = test.insert() # conn.execute(i, x='x', y='z')

# Test if select works without a from clause query = select([text('1 + 1')]) print conn.execute(query).scalar()

query = select( [exists( [test.c.id], and_( test.c.x == 'x', test.c.y == 'y' ) )] ) print conn.execute(query).scalar() finally: metadata.drop_all()

The generated query is:

SELECT EXISTS (SELECT test.id AS id FROM test WHERE test.x = ? AND test.y = ?) FROM (SELECT test.id AS id FROM test WHERE test.x = ? AND test.y = ?)

This is wrong (it works on SQLite but Postgres raises an error). I have tried to add a from_obj=[], but it does not works.