Hello everyone,

A couple of days ago I got challenged with a problem where I needed to
update a large amount of values in a table with the values from other
tables, I was just wondering though... is that at all possible with
the normal SQLAlchemy syntax?

Most large databases (atleast Postgres, MySQL and Oracle) have support
for statements like these, but I have not yet been able to get it to
work properly with the regular SQLAlchemy update syntax.

In Postgres syntax I would like to produce a query like this:
UPDATE some_table
SET value = (a.value * b.value)
FROM some_table a, some_table b
WHERE some_table.entity_id = a.entity_id
AND some_table.entity_id = b.entity_id
AND some_table.attribute_id = 1
AND a.attribute_id = 2
AND b.attribute_id = 3

I have tried things like these:
a = some_table
b = some_table.alias('b')
c = some_table.alias('c')

s = select([b.c.value * c.c.value], and_(
    a.c.entity_id==b.c.entity_id,
    a.c.entity_id==c.c.entity_id,
    a.c.attribute_id==1,
    b.c.attribute_id==2,
    c.c.attribute_id==3,
))
a.update(values={a.c.value: s})

But they don't seem to work, so... is it possible to produce the
syntax as posted above?

Thanks in advance,

Rick van Hattem

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to