Skip to content

Duplicate key values error is not thrown as exception and is getting ignored #255

Open
@flyninjacode

Description

@flyninjacode

I'm trying to capture 'Duplicate key values error ' message if there is any insert statement that is violating the primary key constraint. In the following code I created a 'demo' table with 'demo_id' as the primary_key and tried to insert the same row twice.
Example:
`connection = v.connect()
cursor = connection.cursor()
cursor.execute("""
DROP TABLE IF EXISTS demo;
CREATE TABLE demo (
demo_id integer primary key enabled,
code varchar(20),
quantity smallint,
amount money,
product_id int,
demo_date datetime);
""")
cursor.execute("""
INSERT INTO demo
SELECT 1,'RT0132',1,100,10023,now();

""")
cursor.execute("""
INSERT INTO demo
SELECT 1,'RT0132',1,100,10023,now();

""")
connection.commit()`
For the above code I would expect it to throw an Exception like "Message: b"Duplicate key values: 'demo_id=1' -- violates constraint", but it doesn't. Is there an existing solution to handle this case or can this issue be resolved by doing some quick workaround ?

I'm using Python 3.5.2 and vertica_python 0.8.2 versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions