-1

I'd like to write a script to convert from a relational database to a flat one and vice-versa. The database's rows mostly contain data from text input, but there are a few dropdown lists from the form that enter the primary IDs of a row from another table. Currently I have database rows that would look like say:

(1, 4, 2, 45.508582, -73.610102, 3) that I want turned into:

(1, Sherbrooke, "Park Frontenac", 45.508582, -73.610102, John, Doe) and this back to the above.

Some tables contain one column per primary ID (like city and park tables), but others have 2 or more (like the persons table).

What's the easiest way to write a script for this? I'm not comfortable with scripting outside of basic php, although I plan to start learning python soon.

4

1 回答 1

0

进行 SQL 查询以提供所需的数据

select name1, name2, number1, number2
from table1
join table2 on table1.id = table2.t1_id

并使用 sqlalchemy 将创建并运行您的脚本

from sqlalchemy import create_engine

engine = create_engine('user_pass_address_port')
dbc = engine.connect()
dbr = dbc.execute(sql)
for row in dbr:
    print row

每行都有包含所需数据的元组

于 2011-07-18T06:08:20.180 回答