'SQL why duplicates when executing in Python?

I am writing a small script to insert data into postgres. Here is the structure of my table:

CREATE TABLE  stage (
    a VARCHAR(1),
    b VARCHAR(5) ,
    c VARCHAR(10) ,
    d VARCHAR(20) PRIMARY KEY);

When I execute the following insert statement I do not produce any duplicates.

INSERT INTO stage VALUES ('value_a', 
                          'value_b',
                          'value_c',
                          'value_d' )
ON CONFLICT  DO NOTHING;

Now when I try to execute something similar in Python I'm getting duplicates.

from psycopg2.extras import execute_values

list_ = []
for i in merged_dict.values():
    list_.append((i['a'],i['b'],i['c'],i['d'] ))

insert_query = b'INSERT INTO stage (a, b, c, d) VALUES %s ON CONFLICT DO NOTHING;'

print(insert_query)

# Here is the output from print(insert_query)
b'insert into stage_bloomberg_etp_tick (a, b, c, d) values %s ON CONFLICT DO NOTHING;'

execute_values(cursor, 
               insert_query, 
               list_, 
               template=None, 
               page_size=100)
conn.commit()
conn.close()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source