#19726: Ordering on booleans works different with SQLite and Postgres -------------------------------------+------------------------------------- Reporter: anonymous | Owner: nobody Type: Uncategorized | Status: closed Component: Database layer | Version: 1.4 (models, ORM) | Severity: Normal | Resolution: wontfix Keywords: | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by felipeochoa): I just solved this by annotating the model as follows: {{{ Transaction.objects.annotate( submitted_as_0_1=Case(When(submitted=True, then=Value(1)), default=Value(0), output_field=PositiveSmallIntegerField()) ).order_by('submitted_as_0_1') }}} Maybe we can extend `order_by` to automate this translation: There could be a double-underscore extension like `__as_0_1` that one could use in `order_by` fields that would be automatically converted into this annotation. I haven't benchmarked the performance impact of this change, but since it's an opt-in feature, users can make their own decisions. -- Ticket URL: <https://code.djangoproject.com/ticket/19726#comment:4> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.33bff5396443b306a368bec5f0ebaf2c%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.