From: | Sam Mason <sam(at)samason(dot)me(dot)uk> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to send multiple SQL commands from Python? |
Date: | 2009-10-11 22:45:08 |
Message-ID: | 20091011224508.GJ5407@samason.me.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Christophe Pettus | 2009-10-12 00:27:01 | Re: Building PG 8.4.1 with ossp-uuid on Centos 5.3 |
Previous Message | SunWuKung | 2009-10-11 22:21:05 | Re: strange plpgsql error |