The problem is that the book does not mention it clearly. This is the correct behavior because remember rows may be result of a join and contain columns form multiple tables.
On Nov 30, 10:06 am, olifante <[email protected]> wrote: > Hi all, > > I tried to filter the columns shown by SQLTABLE by adding an explicit > "columns" parameter: > > {{=SQLTABLE(rows,headers=headers,columns=['id', 'my_field_name'])}} > > It turns out that this doesn't work, and results in an Internal Error, > with the ticket pointing to an vague "KeyError: '_extra' " in gluon/ > sql.py > > Reading the sql.py code, I discovered that SQLTABLE expects the > columns parameter to be a list of column names prefixed with the table > name. Changing the code to use the prefixed column names solved the > problem: > > {{=SQLTABLE(rows,headers=headers,columns=['my_table.id', > 'my_table.my_field_name'])}} > > However, this forces you to manually insert the table name, which is > ugly. A better example would extract the table name from the rows > object (BTW, isn't there a more direct way to get the table name?): > > {{tablename = rows.records[0].keys()[0]}} > {{prefixed_columns = ["%s.%s" % (tablename, col) for col in columns]}} > {{=SQLTABLE(rows,headers=headers,columns=prefixed_columns)}} > > This behaviour of the columns parameter struck me as unintuitive, and > the web2py book doesn't mention this important detail. It would be > better to either change the behaviour of the columns parameter or > explicitly document this in the web2py docs and book.

