Style formating of multiline query, advise

Scott David Daniels Scott.Daniels at Acm.Org
Wed Mar 18 12:56:09 EDT 2009


someone wrote:
> what is good :) style for multiline queries to database?...
> 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;"""

Also, for SQL, (A) why are you using nested joins?, and
(B) always show what columns you want as output.  SELECT * is a hack
to make interactive use easier, not a durable way to write queries.

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

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list