Search code examples
pythonsqlpeewee

Peewee Select * and additional fields


I would like to do something like:

select *, concat(firstname, lastname) from user;

I understand you can do the following for select *:

User.select()

Is it possible to do something like:

User.select(User.*, fn.Concat(User.firstname, User.lastname))

Is there a way to do this without explicitly selecting all the columns individually?


Solution

  • Try:

    User.select(User, fn.CONCAT(User.firstname, User.lastname).alias('fullname'))
    

    (I'm using the model class to indicate I want all the fields from that model)