Comparing django:8b020f2e64...dvarrazzo:psycopg3-4.1 · django/django

Commits on Nov 22, 2021

  1. Configuration menu

    Browse the repository at this point in the history

  2. Configuration menu

    Browse the repository at this point in the history

  3. Configuration menu

    Browse the repository at this point in the history

  4. Configuration menu

    Browse the repository at this point in the history

  5. Configuration menu

    Browse the repository at this point in the history

  6. Configuration menu

    Browse the repository at this point in the history

  7. Configuration menu

    Browse the repository at this point in the history

  8. Configuration menu

    Browse the repository at this point in the history

  9. Configuration menu

    Browse the repository at this point in the history

  10. Configuration menu

    Browse the repository at this point in the history

  11. Add supports_order_column_alias database feature.

    This features is necessary for database drivers implementing server-side
    binding (at least it is for PostgreSQL). The problem is around
    sorting on expressions. For instance, with the query:
    
        SELECT sum(value) FROM testdata
        GROUP BY left(name, %s)
        ORDER BY left(name, %s)
    
    If the query is composed client-side, the server is able to infer that
    the group by and the order by are the same expression. If the argument
    is passed to the server as a single copy and several placeholders refer
    to it, it works too, for instance the following works well:
    
        cursor.execute(
            """
            SELECT sum(value) FROM testdata
            GROUP BY left(name, %(num)s)
            ORDER BY left(name, %(num)s)
            """,
            {"num": 3})
    
    But if only positional arguments are passed,
    
        cursor.execute(
            """
            SELECT sum(value) FROM testdata
            GROUP BY left(name, %s)
            ORDER BY left(name, %s)
            """,
            [3, 3])
    
    then PostgreSQL will not be able to infer that the group by and the
    order by are the same expression and will fail with
    
        column "testdata.name" must appear in the GROUP BY clause or be used in
        an aggregate function
    
    If a backend is declared 'supports_order_column_alias', then the query is
    rewritten as:
    
        cursor.execute(
            """
            SELECT sum(value) FROM testdata
            GROUP BY left(name, %s)
            ORDER BY 1
            """,
            [3])
    
    avoiding the problem.
    Configuration menu

    Browse the repository at this point in the history

  12. Configuration menu

    Browse the repository at this point in the history

  13. Configuration menu

    Browse the repository at this point in the history

  14. Configuration menu

    Browse the repository at this point in the history

  15. Configuration menu

    Browse the repository at this point in the history

  16. Configuration menu

    Browse the repository at this point in the history

  17. Configuration menu

    Browse the repository at this point in the history

  18. Configuration menu

    Browse the repository at this point in the history

  19. Configuration menu

    Browse the repository at this point in the history