Search Postgresql Archives

Re: PLPython function and multiple line insert

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

 



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



--
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