Style formating of multiline query, advise
tino at wildenhain.de
Wed Mar 18 16:04:28 CET 2009
John Machin wrote:
> 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
> LIMIT %s;
And I'd not recomment SELECT * for anything beside test queries in an
interactive session or if you are going to copy tables...
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
More information about the Python-list