db.define_table('x',*[Field(y) for y in list_of_field_names])
y = 'a_field_name'
rows = db(db.x).select(db.x[y])
On Jan 24, 7:38 am, Markus Schmitz <[email protected]> wrote:
> Hi everybody,
>
> I have the requirement to treat a range of table fields like an array.
> Example:
>
> I have a table x with fields y1, y2, ...., y100. In normal SQL I could
> create the table by issuing an 'alter table x add field y...'
> statement in a loop and I would be able to access the fields by
> constructing the appropriate SQL command in a string.
>
> So instead of using an index i and writing in theory: select y[i]
> from x
> I would write: ExecuteSQL("select y" + i + " from x)"
>
> But in web2py:
>
> Question 1: How can I create such a table definition in web2py without
> listing all fields manually?
>
> Question 2: How can I use the DAL to access these fields using an
> index and avoid using the ExecuteSQL method?
>
> Thanks in advance,
>
> Markus
>
> P.S.: I know I could simply create a small table, having two fields,
> basically "i" and "y", where "i" is part of the index. But in my case
> I end up with millions of records and quite an overhead for each data
> point. I tried it and performance was not satisfactory. But I am open
> for alternative suggestions.