How to insert ' into postgresql?
<p>I use <code>python</code> package <code>psycopg2</code> to update database.</p>

<pre><code>cur.execute("UPDATE scholars SET name='{}' WHERE id={} and name is null".format(author, scholar_id))
</code></pre>

<p><code>psycopg2.ProgrammingError: syntax error at or near "Neill"
LINE 1: UPDATE scholars SET name='O'Neill, Kevin' WHERE id=12403 and...</code></p>

<p>data should be:<code>O'Neill, Kevin</code></p>

<p>Use <a href="http://initd.org/psycopg/docs/usage.html#query-parameters" rel="nofollow">Psycopg's parameter passing functionality</a>:</p>

<pre><code>cur.execute ("""
    UPDATE scholars 
    SET name = %s 
    WHERE id = %s and name is null
    """,
    (author, scholar_id)
)
</code></pre>

<p><a href="https://docs.python.org/3/tutorial/introduction.html#strings" rel="nofollow">Triple quotes make it clearer</a></p>

python postgresql psycopg2