On Aug 28, 2013, at 10:11 PM, gbr <doubl...@directbox.com> wrote:

> Hi,
> 
> Before spamming the issue tracker and since I'm new to SQLAlchemy and may 
> have misunderstood how to use `append_whereclause()`, I thought I seek 
> confirmation on this mailing list.
> 
> The code:
> 
>     def test_append_whereclause(self):
>         url = 'localhost'
>         username = 'donald'
>         password = 'duck'
>         database_name = 'test_db'
>         engine = create_engine('postgres://%s:%s@%s/%s' % (username, 
> password, url, database_name))
>         session = sessionmaker(bind=engine)()
> 
>         location = Table('location', metadata, 
>             Column('id', Integer, Sequence('seq_location_id')),
>             Column('name', String(256), nullable=False),
>             Column('domestic', Boolean, default=False),
>         )
>         
>         query = select(
>             columns=[location.c.id.label('id')],
>             from_obj=location,
>             whereclause=location.c.id>50
>         )
>         query.append_whereclause(query.c.id < 100)


well you're creating a cycle here by embedding a column with a parent of select 
object "q", in the WHERE clause of select object "q".  to compile the WHERE 
clause of "query" means we look at "query.c.id" which means we must render the 
table "query" which is how it cycles.    Whether or not this kind of thing can 
be faithfully detected (a simple self-referential cycle is one thing, but a 
more deeply nested cycle would be more expensive to detect), from a usage 
standpoint the operation does not make sense.

suppose "query" is this:

SELECT id FROM table

query.c.id is basically this column:

SELECT ---> id <---  FROM (SELECT id FROM table)

that is, it's on the outside of "query" - it's one of the columns it exports.  
it doesn't make any sense to refer to it in the WHERE clause of the embedded 
query.

What it seems like you're looking to do is where(location.c.id < 100).


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to