Search Postgresql Archives

Re: How to send multiple SQL commands from Python?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux