Style formating of multiline query, advise
someone
petshmidt at googlemail.com
Wed Mar 18 11:24:06 EDT 2009
On Mar 18, 2:51 pm, John Machin <sjmac... at lexicon.net> wrote:
> On Mar 18, 11:25 pm, someone <petshm... at googlemail.com> 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 (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,
thanks for reply.
So, no indentation? query is inside of function, of course.
> 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;
> """
>
> Cheers,
> John
More information about the Python-list
mailing list