DISTINCT ON fields is not supported by this database backend

后端 未结 1 1458
说谎
说谎 2020-12-19 05:35

I am using distinct to get the distinct latest values but it is giving me an error:

DISTINCT ON fields is not supported by this database backend

<
相关标签:
1条回答
  • 2020-12-19 06:29

    distinct('field_name') is not supported in MySQL. It only support distinct(). distinct('field_name') will only work on PostgresSQL. For more details, please check the documentation.

    Examples (those after the first will only work on PostgreSQL):(Copy Pasted from Documentation:)

    >>> Author.objects.distinct() 
       [...]
    
    >>> Entry.objects.order_by('pub_date').distinct('pub_date')
       [...]
    
    >>> Entry.objects.order_by('blog').distinct('blog')
       [...]
    
    >>> Entry.objects.order_by('author', 'pub_date').distinct('author', 'pub_date')
       [...]
    
    >>> Entry.objects.order_by('blog__name', 'mod_date').distinct('blog__name', 'mod_date')
       [...]
    
    >>> Entry.objects.order_by('author', 'pub_date').distinct('author')
       [...]
    
    0 讨论(0)
提交回复
热议问题