psycopg2 equivalent of mysqldb.escape_string?

后端 未结 5 582
迷失自我
迷失自我 2020-12-10 23:53

I\'m passing some values into a postgres character field using psycopg2 in Python. Some of the string values contain periods, slashes, quotes etc.

With MySQL I\'d ju

5条回答
  •  [愿得一人]
    2020-12-11 00:40

    Psycopg2 doesn't have such a method. It has an extension for adapting Python values to ISQLQuote objects, and these objects have a getquoted() method to return PostgreSQL-compatible values.

    See this blog for an example of how to use it:

    Quoting bound values in SQL statements using psycopg2

    Update 2019-03-03: changed the link to archive.org, because after nine years, the original is no longer available.

提交回复
热议问题