Max columns using table () for SQLAlchemy Core - Python
I am using SQLAlchemy Core in Python to build MySQL tables. I am using Table () function like this:
http://docs.sqlalchemy.org/en/latest/core/tutorial.html#define-and-create-tables
As you can see, each column is specified as an argument to the function. The problem is that Python functions handle a maximum of 255 arguments, but I need to build a table with 400 arguments. Is there a way to get around the argument limitation in Python? Or perhaps another function that I can use to build the table? I tried to list the columns / arguments, but that didn't work.
Thank!
Edit: I'm trying to use the same table format () as in the Core SQLAlchemy tutorial. For example:
addresses = Table('addresses', metadata,
Column('id', Integer, primary_key=True),
Column('user_id', None, nullable=False),
Column('email_address', String, nullable=False))
This use of table () will create three columns, obviously. However, I want to create 397 more (different) columns, but I can't, because Table () will only take 255 arguments. How to get around this?
source to share
Does this seem to be working fine?
What's your problem?
EDIT
from sqlalchemy import Table, Column, Integer, String, MetaData
metadata = MetaData()
hello = [Column('x{}'.format(i), String, nullable=False) for i in range(1000)]
t = Table('t', metadata, *hello)
print t.__dict__
print t.__dict__.get("_columns")
#{'schema': None, '_columns': <sqlalchemy.sql.base.ColumnCollection object at 0x026C68A0>, 'name': 't', 'dispatch': <sqlalchemy.event.base.DDLEventsDispatch object at 0x02133B70>, 'indexes': set([]), 'foreign_keys': set([]), 'columns': <sqlalchemy.sql.base.ImmutableColumnCollection object at 0x02717300>, '_prefixes': [], '_extra_dependencies': set([]), 'fullname': 't', 'metadata': MetaData(bind=None), 'implicit_returning': True, 'constraints': set([PrimaryKeyConstraint()]), 'primary_key': PrimaryKeyConstraint()}
#['t.x0', 't.x1', 't.x2', 't.x3', 't.x4', 't.x5', 't.x6', 't.x7', 't.x8', 't.x9', 't.x10', 't.x11', 't.x12', 't.x13', 't.x14', 't.x15', 't.x16', 't.x17', 't.x18', 't.x19', 't.x20', 't.x21', 't.x22', 't.x23', 't.x24', 't.x25', 't.x26', 't.x27', 't.x28', 't.x29', 't.x30', 't.x31', 't.x32', 't.x33', 't.x34', 't.x35', 't.x36', 't.x37', 't.x38', 't.x39', 't.x40', 't.x41', 't.x42', 't.x43', 't.x44', 't.x45', 't.x46', 't.x47', 't.x48', 't.x49', 't.x50', 't.x51', 't.x52', 't.x53', 't.x54', 't.x55', 't.x56', 't.x57', 't.x58', 't.x59', 't.x60', 't.x61', 't.x62', 't.x63', 't.x64', 't.x65', 't.x66', 't.x67', 't.x68', 't.x69', 't.x70', 't.x71', 't.x72', 't.x73', 't.x74', 't.x75', 't.x76', 't.x77', 't.x78', 't.x79', 't.x80', 't.x81', 't.x82', 't.x83', 't.x84', 't.x85', 't.x86', 't.x87', 't.x88', 't.x89', 't.x90', 't.x91', 't.x92', 't.x93', 't.x94', 't.x95', 't.x96', 't.x97', 't.x98', 't.x99', 't.x100', 't.x101', 't.x102', 't.x103', 't.x104', 't.x105', 't.x106', 't.x107', 't.x108', 't.x109', 't.x110', 't.x111', 't.x112', 't.x113', 't.x114', 't.x115', 't.x116', 't.x117', 't.x118', 't.x119', 't.x120', 't.x121', 't.x122', 't.x123', 't.x124', 't.x125', 't.x126', 't.x127', 't.x128', 't.x129', 't.x130', 't.x131', 't.x132', 't.x133', 't.x134', 't.x135', 't.x136', 't.x137', 't.x138', 't.x139', 't.x140', 't.x141', 't.x142', 't.x143', 't.x144', 't.x145', 't.x146', 't.x147', 't.x148', 't.x149', 't.x150', 't.x151', 't.x152', 't.x153', 't.x154', 't.x155', 't.x156', 't.x157', 't.x158', 't.x159', 't.x160', 't.x161', 't.x162', 't.x163', 't.x164', 't.x165', 't.x166', 't.x167', 't.x168', 't.x169', 't.x170', 't.x171', 't.x172', 't.x173', 't.x174', 't.x175', 't.x176', 't.x177', 't.x178', 't.x179', 't.x180', 't.x181', 't.x182', 't.x183', 't.x184', 't.x185', 't.x186', 't.x187', 't.x188', 't.x189', 't.x190', 't.x191', 't.x192', 't.x193', 't.x194', 't.x195', 't.x196', 't.x197', 't.x198', 't.x199', 't.x200', 't.x201', 't.x202', 't.x203', 't.x204', 't.x205', 't.x206', 't.x207', 't.x208', 't.x209', 't.x210', 't.x211', 't.x212', 't.x213', 't.x214', 't.x215', 't.x216', 't.x217', 't.x218', 't.x219', 't.x220', 't.x221', 't.x222', 't.x223', 't.x224', 't.x225', 't.x226', 't.x227', 't.x228', 't.x229', 't.x230', 't.x231', 't.x232', 't.x233', 't.x234', 't.x235', 't.x236', 't.x237', 't.x238', 't.x239', 't.x240', 't.x241', 't.x242', 't.x243', 't.x244', 't.x245', 't.x246', 't.x247', 't.x248', 't.x249', 't.x250', 't.x251', 't.x252', 't.x253', 't.x254', 't.x255', 't.x256', 't.x257', 't.x258', 't.x259', 't.x260', 't.x261', 't.x262', 't.x263', 't.x264', 't.x265', 't.x266', 't.x267', 't.x268', 't.x269', 't.x270', 't.x271', 't.x272', 't.x273', 't.x274', 't.x275', 't.x276', 't.x277', 't.x278', 't.x279', 't.x280', 't.x281', 't.x282', 't.x283', 't.x284', 't.x285', 't.x286', 't.x287', 't.x288', 't.x289', 't.x290', 't.x291', 't.x292', 't.x293', 't.x294', 't.x295', 't.x296', 't.x297', 't.x298', 't.x299'.....]
In the above example, I am using a list comprehension to create 1000 columns and pass it to my table. You will need to define each one one by one.
Also, it should be noted that a 400-column table is not necessarily a good idea, and you should probably plan on how to efficiently create multiple tables rather than one large table.
source to share