Hi Michael, thanks, that was the example I was looking for. So I only need to specify the columns, I want to alter and are using within the where statement.
Kind regards Cornelius Am 01.04.2012 17:28, schrieb Michael Bayer: > are you running from within an Alembic migration ? Otherwise > wondering why you're generating an engine and all that, all of that is > a given within Alembic migration scripts. > > An update is done via the update() method but there's no need to > generate a whole Table like that (you only need the columns that will > be rendered in the SQL) and obviously all the connection boilerplate > goes away and you just use op.execute(), see the example in > http://alembic.readthedocs.org/en/latest/ops.html#alembic.operations.Operations.execute. > > > > On Apr 1, 2012, at 11:07 AM, Cornelius Kölbel wrote: > > > Hello again, > > > ok, it could work this way: > > > > import sqlalchemy as sa > > from alembic import context > > > config = context.config > > engine = sa.engine_from_config( > > config.get_section(config.config_ini_section), > > prefix='sqlalchemy.') > > engine.echo = False > > metadata = sa.MetaData(engine) > > token = sa.Table('Token', metadata, autoload=True) > > upd = > > > token.update(values={token.c.Count:token.c.Count+1}).where(token.c.TokenId > >> 200) > > engine.execute(upd) > > > > ...but I wonder, if there would be less lines of code... > > > Kind regards > > Cornelius > > > Am 01.04.2012 08:48, schrieb Cornelius Koelbel: > >> Hi, > >> > >> yesterday i stumbled upon alembic to upgrade the database schema. It > >> looks very promising and I am evaluating what is possible with what > kind > >> of effort. > >> > >> What would be the easiest way to update table contents within alembic > >> like this: > >> > >> update test set name='Fred' where name='fred' > >> > >> ...or one day even more complex! ;-) > >> > >> Kind regards > >> Cornelius > >> > > > > -- Cornelius Kölbel (Senior Security Consultant, Head of Product Management) http://www.lsexperts.de LSE Leading Security Experts GmbH, Postfach 100121, 64201 Darmstadt Tel: +49 6151 9067-252, Fax: -299, Mobil: +49 160 96307089 Unternehmenssitz: Weiterstadt, Amtsgericht Darmstadt: HRB8649 Geschaeftsfuehrer: Oliver Michel, Sven Walther, Dr. Peter Schill
signature.asc
Description: OpenPGP digital signature
