[Python] Ordering data after distinct

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    I distinct data by sku_id

    queryset = self.filter_queryset(queryset.order_by('sku_id','id').distinct('sku_id'))


    However this result is not sorted by id,

    then I try to

    queryset = self.filter_queryset(queryset.order_by('sku_id','id').distinct('sku_id').order_by('id'))


    However this shows the error

    ProgrammingError at /api/myfetch/
    SELECT DISTINCT ON expressions must match initial ORDER BY expressions
    LINE 1: SELECT COUNT(*) FROM (SELECT DISTINCT ON ("myapp_produc...


    Is it possible to sort the column after distinct?

    Continue reading...

Compartilhe esta Página