Re: How to send multiple SQL commands from Python?

Поиск
Список
Период
Сортировка
От Sam Mason
Тема Re: How to send multiple SQL commands from Python?
Дата
Msg-id 20091011224508.GJ5407@samason.me.uk
обсуждение исходный текст
Ответ на Re: How to send multiple SQL commands from Python?  (Adrian Klaver <aklaver@comcast.net>)
Список 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 по дате отправления:

Предыдущее
От: SunWuKung
Дата:
Сообщение: Re: strange plpgsql error
Следующее
От: Christophe Pettus
Дата:
Сообщение: Re: Building PG 8.4.1 with ossp-uuid on Centos 5.3