Style formating of multiline query, advise

John Machin sjmachin at
Wed Mar 18 14:51:35 CET 2009

On Mar 18, 11:25 pm, someone <petshm... at> wrote:
> Hi,
> what is good :) style for multiline queries to database?
> Is that one ok?
> query = """ SELECT * FROM (
>                    SELECT a.columna, a.columnb, a.iso
>                       FROM all a
>                       WHERE ( = LOWER(%s))  ) AS c
>                  JOIN other as b on c.gid =
>                  WHERE class = 'A'
>                  ORDER BY population DESC
>                  LIMIT %s;"""

There's no tablet of stone, like PEP 8 :-) It seems to be a matter of
individual taste; clarity and consistency and not overdoing
parentheses count for me.

IMO you have too much leading whitespace, you have "as" in upper,
lower and no case, and I'd set out the inner select differently:

query = """
        SELECT a.columna, a.columnb, a.iso
        FROM all AS a
        WHERE = LOWER(%s)
        ) AS c
    JOIN other AS b ON c.gid =
    WHERE class = 'A'
    ORDER BY population DESC
    LIMIT %s;


More information about the Python-list mailing list