Re: How to send multiple SQL commands from Python? - Mailing list pgsql-general

From Sam Mason
Subject Re: How to send multiple SQL commands from Python?
Date
Msg-id 20091011224508.GJ5407@samason.me.uk
Whole thread Raw
In response to Re: How to send multiple SQL commands from Python?  (Adrian Klaver <aklaver@comcast.net>)
List pgsql-general
On Sat, Oct 10, 2009 at 01:14:56PM -0700, Adrian Klaver wrote:
> sql_str = "ALTER TABLE " + $xn + " OWNER TO xdev;"
> sql_str += "GRANT ALL ON TABLE " + $xn + " TO xdev;"
> sql_str += "REVOKE ALL ON TABLE " + $xn + " FROM PUBLIC;"
> sql_str += "GRANT SELECT ON TABLE " + $xn + " TO PUBLIC;"

One minor stylistic point.  Python appears to follow the same string
literal rules as C in that multiple adjacent string literals are
concatenated at compile time[1].  Thus you could write the above as:

  sql_str = (
    "ALTER TABLE " + $xn + " OWNER TO xdev;"
    "GRANT ALL ON TABLE " + $xn + " TO xdev;"
    "REVOKE ALL ON TABLE " + $xn + " FROM PUBLIC;"
    "GRANT SELECT ON TABLE " + $xn + " TO PUBLIC;"
    );

This wouldn't help much here, but may in more complicated bits of code.

--
  Sam  http://samason.me.uk/

 [1] http://docs.python.org/reference/lexical_analysis.html#string-literal-concatenation

pgsql-general by date:

Previous
From: SunWuKung
Date:
Subject: Re: strange plpgsql error
Next
From: Christophe Pettus
Date:
Subject: Re: Building PG 8.4.1 with ossp-uuid on Centos 5.3