Style formating of multiline query, advise
sjmachin at lexicon.net
Wed Mar 18 14:51:35 CET 2009
On Mar 18, 11:25 pm, someone <petshm... at googlemail.com> wrote:
> 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 (a.name = LOWER(%s)) ) AS c
> JOIN other as b on c.gid = b.id
> 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 * FROM (
SELECT a.columna, a.columnb, a.iso
FROM all AS a
WHERE a.name = LOWER(%s)
) AS c
JOIN other AS b ON c.gid = b.id
WHERE class = 'A'
ORDER BY population DESC
More information about the Python-list