Bulk creation of columns

40 views
Skip to first unread message

pravin battula

unread,
Sep 23, 2011, 3:13:03 AM9/23/11
to migrate-users
Hi,
How can i create columns in bulk using create_column method?
I tried as below,.
migrate_engine = create_engine('mysql://root:root@localhost/
payroll', echo=False)
metadata = MetaData(bind = migrate_engine)
metadata.reflect(bind = migrate_engine, schema = 'payroll')
tableObj = metadata.tables.get('test.salary')
colList =
[Column('description',String(100)),Column('information',String(50))]
tableObj.append_column(*colList)
tableObj.create_column(*colList)

getting an error as *TypeError*:*create() got multiple values for
keyword
argument 'table'*

Please do the needful.

Jan Dittberner

unread,
Sep 23, 2011, 6:49:25 AM9/23/11
to migrate-users
You might want to use a for loop like:

for col in
[Column('description',String(100)),Column('information',String(50))]:
tableObj.append_column(col)
tableObj.create_column(col)

Regards,
Jan Dittberner

pravin battula

unread,
Sep 23, 2011, 7:11:57 AM9/23/11
to migrate-users
Jan,

that is the same thing i have done as of now but was worried in terms
of performance if the table has thousands of data in it.
is there any efficient way of doing it,something like passing a list
and executing as below.
1. ALTER TABLE emp
2 ADD ( city_name varchar2(10),
3 role varchar2(10) );


Regards
Pravin B

On Sep 23, 3:49 pm, Jan Dittberner <jan.dittber...@googlemail.com>
wrote:

Jan Dittberner

unread,
Sep 23, 2011, 3:19:25 PM9/23/11
to migrat...@googlegroups.com
Hello Pravin,

I think it would be better to

1) create a new table with all required columns
2) copy the data from the old table
3) drop the old table
4) rename the new table to the desired name

As far as I know none of the databases that sqlalchemy-migrate
supports does have a DDL statement to add multiple columns at once.
Therefore it does not make sense to support something like that at
Python level and give the treacherous impression that it will be
faster than using multiple ALTER TABLE statements.


Regards
Jan Dittberner

2011/9/23 pravin battula <pravin....@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "migrate-users" group.
> To post to this group, send email to migrat...@googlegroups.com.
> To unsubscribe from this group, send email to migrate-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/migrate-users?hl=en.
>
>

--
Jan Dittberner
Software Architect - Debian Developer

pravin battula

unread,
Sep 26, 2011, 2:08:11 AM9/26/11
to migrate-users
Jan,

I have tested the below code in mysql for adding multiple column and
it works.

ALTER TABLE employee ADD city_name VARCHAR(60),ADD role VARCHAR(100).


On Sep 24, 12:19 am, Jan Dittberner <jan.dittber...@googlemail.com>
wrote:
> Hello Pravin,
>
> I think it would be better to
>
> 1) create a new table with all required columns
> 2) copy the data from the old table
> 3) drop the old table
> 4) rename the new table to the desired name
>
> As far as I know none of the databases that sqlalchemy-migrate
> supports does have a DDL statement to add multiple columns at once.
> Therefore it does not make sense to support something like that at
> Python level and give the treacherous impression that it will be
> faster than using multiple ALTER TABLE statements.
>
> Regards
> Jan Dittberner
>
> 2011/9/23 pravin battula <pravin.batt...@gmail.com>:
> > For more options, visit this group athttp://groups.google.com/group/migrate-users?hl=en.

Jan Dittberner

unread,
Sep 26, 2011, 5:08:45 AM9/26/11
to migrat...@googlegroups.com
Hello,

seems like PostgreSQL does support this syntax too [1]. SQLite does
not support it [2]. If you would really want to have such support in
sqlalchemy-migrate please file a ticket in our issue tracker [3]
(ideally with a patch and test cases attached :-) )

[1] http://www.postgresql.org/docs/8.2/static/sql-altertable.html
[2] http://sqlite.org/lang_altertable.html
[3] http://code.google.com/p/sqlalchemy-migrate/issues/list

Kind Regards
Jan Dittberner

2011/9/26 pravin battula <pravin....@gmail.com>:

> For more options, visit this group at http://groups.google.com/group/migrate-users?hl=en.

Reply all
Reply to author
Forward
0 new messages