[sqlalchemy] Re: quick question...
and what this is expected to do? x = task and (max(task.sequence)+100) or 100 ? Jonathan LaCour wrote: I have been banging my head against the wall for a little bit attempting to translate this SQL: SELECT max(value) FROM ( SELECT max(sequence)+100 as value FROM task UNION SELECT 100.0 as value ) into an SQLAlchemy expression that I can embed into an INSERT. Should I just go ahead an use text() rather than bother with attempting to construct this using an SQLAlchemy expression? (Yes, I know that this is gross...) -- Jonathan LaCour http://cleverdevil.org --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: quick question...
unfortunately it requires a bugfix, r4031: s = select([(func.max(task.c.sequence) +100).label('value')]).union(select([literal(100.0).label('value')])) print select([func.max(s.c.value)]) On Jan 8, 2008, at 4:37 PM, Jonathan LaCour wrote: I have been banging my head against the wall for a little bit attempting to translate this SQL: SELECT max(value) FROM ( SELECT max(sequence)+100 as value FROM task UNION SELECT 100.0 as value ) into an SQLAlchemy expression that I can embed into an INSERT. Should I just go ahead an use text() rather than bother with attempting to construct this using an SQLAlchemy expression? (Yes, I know that this is gross...) -- Jonathan LaCour http://cleverdevil.org --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: quick question...
On Jan 8, 2008, at 5:05 PM, Jonathan LaCour wrote: Michael Bayer wrote: unfortunately it requires a bugfix, r4031: s = select([(func.max(task.c.sequence) +100).label('value')]).union(select([literal(100.0).label('value')])) print select([func.max(s.c.value)]) Thanks Mike. My unit test now gets past the SQL generation, but still fails. It appears that the SQL gets generated and run, but the value doesn't show up in the database as expected. Note: I am using this SQL expression as part of an insert by setting it directly on my mapped object: task = Task() task.sequence = crazy sql expression session.save(task) Might this have something to do with it? sure...what do your SQL logs say ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: quick question...
Michael Bayer wrote: sure...what do your SQL logs say ? 2008-01-08 17:41:21,832 INFO sqlalchemy.engine.base.Engine.0x..50 INSERT INTO task (sequence, subject, description, due_date, reminder, private, company_id, assigned_to_id, job_id) VALUES ((SELECT max(task.sequence) + ? AS value FROM task UNION SELECT ? AS value), ?, ?, ?, ?, ?, ?, ?, ?) 2008-01-08 17:41:21,833 INFO sqlalchemy.engine.base.Engine.0x..50 [100, '100.0', 'Item One', None, None, None, None, 1, None, None] -- Jonathan LaCour http://cleverdevil.org --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: quick question...
On Jan 8, 2008, at 5:42 PM, Jonathan LaCour wrote: Michael Bayer wrote: sure...what do your SQL logs say ? 2008-01-08 17:41:21,832 INFO sqlalchemy.engine.base.Engine.0x..50 INSERT INTO task (sequence, subject, description, due_date, reminder, private, company_id, assigned_to_id, job_id) VALUES ((SELECT max(task.sequence) + ? AS value FROM task UNION SELECT ? AS value), ?, ?, ?, ?, ?, ?, ?, ?) 2008-01-08 17:41:21,833 INFO sqlalchemy.engine.base.Engine.0x..50 [100, '100.0', 'Item One', None, None, None, None, 1, None, None] soits missing the outermost SELECT ? try an alias ? also, i think a CASE statement might be the better choice here to get the hardcoded 100 in there perhaps ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---