cancel
Showing results for 
Search instead for 
Did you mean: 

Exception: unique constraint violated: Table (xxxxx)

Former Member
0 Kudos

Dear all, I hope someone can help

When I attempt to load data into my table, i receive this message, and also now get it when performing a check on the .hdbtim file

ERROR      playpen/db/ZGS.hdbtim

           Repository: Internal error during statement execution, please see the database error traces for additional details An error occurred when inserting data from csvfile to table. CSV-file: playpen.db:ZGS. Target Table: playpen.db::ZGS Exception:: unique constraint violated: Table(playpen.db::ZGS) at ptime/query/plan_executor/trex_wrapper/trex_wrapper_body/trex_update.cc:1391

I know what is causing it.

I have an Att View which uses my table ZGS, with a join to M_TIME_DIMENSION. Without the join, it works fine.

My table is defined as this, in a .hdbtable

table.columns = [

{name = "MANDT"; sqlType = NVARCHAR; length = 3; nullable = false; comment = "Client"; },

{name = "MATNR"; sqlType = NVARCHAR; nullable = false; length = 18; comment = "Material Number"; },

{name = "CHARG"; sqlType = NVARCHAR; nullable = false; length = 10; comment = "Batch Number"; },

{name = "ADBTH"; sqlType = DATE; nullable = true; comment = "Actual RDR Delivery Date"; }

];

table.primaryKey.pkcolumns = ["MATNR","CHARG"];

My Att View contains the fields from ZGS: MATNR and CHARG, and the field CALMONTH from M_TIME_DIMENSION. The Att View, has MATNR and CHARG as Key Attributes.

It is joined using ZGS-ADBTH to M_TIME_DIMENSION-DATE_SQL.

The Join is Referention, with no Cardinality (the default).

Anyone  ?

Thanks

G

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

This message was moderated.

Former Member
0 Kudos

Hi Glen,

If you have solved this issue, you can ignore it.

I think that you load duplicate data into your table, so please you related data, if you table has no dada, you only check cvs file, otherwise you need to check both (table and cvs).

Hope this can help you.

Regards,

Jerry

Former Member
0 Kudos

see my reply to ravindra

Former Member
0 Kudos

Hi Glen,

Thank you for your information, according to your posted error information, it should be duplicate data issue "unique constraint violated", so I suggested you double checked related data before.

Based on your commends, you can import your csv file by command, then I tested on my test environment, even if the design-time table has used as att view, it also can imported related data to design-time table.

Why you use "date" type as join condition? It is joined using ZGS-ADBTH to M_TIME_DIMENSION-DATE_SQL.

could you test other type suchas integer or varchar as join type to try again.

Hope this can help you .

Regards,

Jerry

Former Member
0 Kudos

i need to retrieve the CALMONTH, from a date, hence the use.

Former Member
0 Kudos

Hi Glen,

As my mention, you can test for other column, you know, the "calmonth" column has duplicate data, though you did not import data to m_time_dimension, I am afraid that it maybe HANA import bug under special situation or landscape, so I suggest that you try other field to test it.

Regards,

Jerry

former_member184768
Active Contributor
0 Kudos

Hi Glen,

I don't think the attribute view might be causing the issue. It is just a view and should not perform unique constraint check. This seems more with the data.

Can I request you to do something to check if there are any duplicate records in the table itself.

  • Please create a table as follows:
  • CREATE COLUMN TABLE T_CHECK ( "MANDT" NVARCHAR(3), "MATNR" NVARCHAR(18), "CHARG" NVARCHAR(10), "ADBTH" DATE );
  • Insert the data to the table T_CHECK
  • Run the following SQL to identify if there are any duplicate values:
  • select "MATNR", "CHARG", count(*) from T_CHECK group by "MATNR", "CHARG" having count(*) > 1;

My doubt is there might be multiple values for MANDT for a given combination of MATNR and CHARG, which is causing the unique key constraint issue. Ideally even MANDT should be part of the primary key.

Regards,

Ravi

Former Member
0 Kudos

hi ravindra

there is only one record in the csv file, and records in the table.

further information, using the IMPORT command via SQLScript, it works fine.

rindia
Active Contributor
0 Kudos

Hi Glen,

When you Import data from CSV to a table, for the very first time it does not throw any error for column store table if you choose proper key and length. As your CSV file contains only one record, obviously your table has one record.

But when you try Import again for an existing table, make sure that your CSV file does not contain the record which is already inserted in table, else you will get unique constraint violation.

Regards

Raj

Former Member
0 Kudos

nope, import into a blank table, you get the error

ta

rindia
Active Contributor
0 Kudos

Glen,

If you can send the CSV file, if possible, I will try to upload and see how it reacts.

Regards

Raj