Return distinct from sql statment odoo 9

420 views Asked by At

I have total 3 row in database and one row where is ID = 1, in console display 3 row instead one!

@api.multi 
    def call_func(self):
        result = []
        for data in self.search([]):
            self._cr.execute('''select distinct
                    date
                from
                    mytable
                 WHERE id = 1''')
            for line in self._cr.dictfetchall():
                print line["date"]

I'm add distinct but not work.

Output is:

2016-01-01 00:00:00
2016-01-01 00:00:00
2016-01-01 00:00:00

I need 2016-01-01 00:00:00

1

There are 1 answers

1
Marc Compte On BEST ANSWER

The SQL statement looks good. Did you execute that statement on the DB server directly using a client? Did you get only one record?

If yes, I think your problem might lie in self.search([]). Is that a function you wrote? does that perform a search on the records? If so, is it possible you are searching based on an empty string and this returns all 3 records of your table?

If self.search([]) returns an array of 3 elements then you are simply doing SELECT distinct on the same row three times.

If that's your problem, then you may fix it by removing this part:

for data in self.search([]):