python - Selecting distinct values from a column in Peewee -
i looking select values 1 column distinct using peewee.
for example if had table
organization year company_1 2000 company_1 2001 company_2 2000 ....
to return unique values in organization column [i.e.company_1
, company_2
]
i had assumed possible using distinct
option documented http://docs.peewee-orm.com/en/latest/peewee/api.html#selectquery.distinct
my current code:
organizations_returned = organization_db.select().distinct(organization_db.organization_column).execute() item in organizations_returned: print (item.organization_column)
does not result in distinct rows returned (it results in e.g. company_1
twice).
the other option tried:
organization_db.select().distinct([organization_db.organization_column]).execute()
included [ ]
within disctinct
option, although appearing more consistent documentation, resulted in error peewee.operationalerror: near "on": syntax error
:
am correct in assume possible return unique values directly peewee - , if so, doing wrong?
model structure:
cd_sql = sqlitedatabase(sql_location, threadlocals=true, pragmas=(("synchronous", "off"),)) class basemodel(model): class meta: database = cd_sql class organization_db(basemodel): organization_column = charfield() year_column = charfield()
so coleifer getting @ sqlite doesn't support distinct on
. that's not big issue though, think can accomplish want so:
organization_db.select(organization_db.organization).distinct()
Comments
Post a Comment