I'm trying to get this code working with peewee:
distinct_list = QSales.select(QSales.account, QSales.tax_code).distinct().where(QSales.trans_num == 3717)
print distinct_list
but the print command result is:
<class '__main__.QSales'> SELECT DISTINCT t1.`Account`, t1.`Tax_Code` FROM `q_sales` AS t1 WHERE (t1.`Trans_#` = %s) [3717]
running the above select statement in MySQL editor (copy the print result to the editor) returns correct result.
I also tried:
distinct_list = QSales.select(fn.Distinct(QSales.account, QSales.tax_code)).where(QSales.trans_num == 3717)
but got the same result
What am I doing wrong?
Thank you.
Peewee is a Python ORM (Object-Relational Mapping) library which supports SQLite, MySQL, PostgreSQL and Cockroach databases. This tutorial will help you to understand how to insert a new record, delete a record, create an index, etc., with the help of Peewee.
Distinct keyword is used in DB and it is to return record set only with distinct elements for that particular column.
Most of the SELECT DISTINCT queries will perform exactly as fast as their simple SELECT counterparts, because the optimizer will do away with the step necessary for eliminating duplicates.
Sleeping over it, I realized that that code should be as follows:
distinct_list = QSales.select(QSales.account, QSales.tax_code).distinct().where(QSales.trans_num == 3717)
for item in distinct_list:
print item.account
print item.tax_code
This is closed now. Thank you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With