0

I have the following table:

my_table = sa.sql.table('my_table',
    sa.Column('id', sa.BigInteger),
    sa.Column('employee_id', sa.BigInteger)
)

and I want to add a 'rank' column using alembic. The addition itself is pretty straight forward using add_column but I also need to populate that column using sqlalchemy based on existing information (each employee_id has its own rank ordered by the id).

For example, the following table:

id    employee_id    rank
--    -----------    ----
1          1          1
2          1          2
5          1          3
3          2          1
4          3          1
6          3          2

The problem is similar to this one.

The only difference is that I need it working for sqlalchemy on top of both mysql and oracle (a more generic solution is needed).

How can I populate the rank column using engine.update?

EDIT 1: This question is not about how to insert or update records through alembic. It's about finding a query that will do a specific thing and running this query using engine.update

Ofir
  • 1,565
  • 3
  • 23
  • 41
  • This is not a question about how to insert/update records through alembic. I've updated my question to reflect that. Please read the entire question before dismissing it. – Ofir Oct 12 '14 at 21:05
  • Then please rewrite the question to focus on the specific problem. Right now it's rather vague. – lxg Oct 12 '14 at 21:24
  • Thanks, I just understood that "Any Thoughts?" is not that focused :) – Ofir Oct 13 '14 at 08:49

0 Answers0