Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with Model.select(SQL('*'))... #395

Closed
goir opened this issue Jul 18, 2014 · 1 comment
Closed

problem with Model.select(SQL('*'))... #395

goir opened this issue Jul 18, 2014 · 1 comment

Comments

@goir
Copy link

goir commented Jul 18, 2014

Hi,

I have a very complex Query and want to use SQL('*') to select all fields to avoid specifying all fields and making the query even longer.
Very basic example:

from peewee import SqliteDatabase, PrimaryKeyField, CharField, Model, SQL, fn

db = SqliteDatabase(':memory:')

class Model1(Model):
    id = PrimaryKeyField()
    column = CharField()

    class Meta(object):
    database = db

Model1.create_table()
Model1.create(id=1, column='bar')
Model1.create(id=2, column='foo')
Model1.create(id=3, column='baz')

res = Model1.select(SQL("*"))
print res
for a in res:
    print a

which results in the following error:

<class '__main__.Model1'> SELECT * FROM "model1" AS t1 []
  File "<path>/tests/bla.py", line 30, in <module>
    for a in res:
  File "<path>/env_local/local/lib/python2.7/site-packages/peewee.py", line 1615, in next
    obj = self.iterate()
  File "<path>/env_local/local/lib/python2.7/site-packages/peewee.py", line 1601, in iterate
    self.initialize(self.cursor.description)
  File "<path>/env_local/local/lib/python2.7/site-packages/peewee.py", line 1643, in initialize
    select_column = self.column_meta[i]
IndexError: list index out of range

i'm using the current master.

Thanks
Goir

@coleifer
Copy link
Owner

Peewee does not currently support this, unfortunately. You can always pass in the model class to .select() and it will select the appropriate columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants