Re: PLPython function and multiple line insert

Поиск
Список
Период
Сортировка
От Igor Katson
Тема Re: PLPython function and multiple line insert
Дата
Msg-id 4A2A7FCD.7030201@gmail.com
обсуждение исходный текст
Ответ на PLPython function and multiple line insert  ("Andi Klapper" <andi.klapper@gmail.com>)
Список pgsql-general
Andi Klapper wrote:
>
>   sql = "("INSERT INTO table1 (field1, field2, field3)
>                VALUES ('abc', 'abc', TRUE),
>                   ('def', 'def', FALSE),
>                   ('ghi', 'ghi', TRUE");"
>   pypl.execute(sql)
> .
> .
> $$
> LANGUAGE 'plpythonu' VOLATILE
>
> I ran into trouble with quoting this SQL statement in PLPython
> (PostgreSQL 8.3.7). Any ideas/suggestions how to quote it either with
> pypl.execute() or pypl.plan()?
The statement looks incorrect from the python point of view (not just
plpython). You should quote multi-lined strings, or use an escape
character (\) like:
"""line 1
line 2"""
'''line 1
line2'''
'line 1\n\
line2'
So I would try to rewrite the statement with:
  sql = """INSERT INTO table1 (field1, field2, field3)
               VALUES ('abc', 'abc', TRUE),
                  ('def', 'def', FALSE),
                  ('ghi', 'ghi', TRUE);"""
  pypl.execute(sql)
>
> Thanks for any suggestions and help in advance,
> Andi
>


В списке pgsql-general по дате отправления:

Предыдущее
От: "Nykolyn, Andrew P (AS)"
Дата:
Сообщение: Upgrade from Postgres 8.2.4 to 8.3.5
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Upgrade from Postgres 8.2.4 to 8.3.5