Updating postgres column using python dataframe
<p>I am generating dataframe (<code>df</code>) for different dates and it will have the following variables</p>

<pre><code>date           value     rowId
2016-05-14       2.5       1
2016-05-14       3.0       2
2016-05-14       3.4       5
</code></pre>

<p>I have to update a column (<code>value</code>) in postgres table (<code>Table1</code>). This table already contains a column (<code>value</code>) of type decimal in (<code>Table1</code>) along with unique identifier (<code>rowId</code>)</p>

<pre><code>for d in range(0,len(df)):
        QUERY=""" UPDATE "Table1" SET "value"='%s' WHERE "Table1"."rowId"='%s'
            """ % (df['value'][d], df['rowId'][d])
        cur.execute(QUERY)
</code></pre>

<p>There is no error. However, the above code is not updating the column in Postgres table. Is there any error in the code?</p>

<p>Well, closing transaction with commit should help. I'm not sure if you are using <code>psycopg2</code>, or any other library which has a <code>commit()</code> function. If not, then a simple <code>cur.execute('COMMIT')</code> should be enough. This should be run right after the <code>for</code> loop.</p>

python sql postgresql dataframe