I've created a Ignite table via defining two columns as primary key (PK). When I tried to insert the data its failing with duplicate key error. PK defined on type and id column.
0: jdbc:ignite:thin://node1.example.com> insert into balance (type,amount,currency,asof,id) values ('Current Balance',20000.1,'INR','2020-04-07 00:00:00.000','1009230183926');
1 row affected (0.036 seconds)
0: jdbc:ignite:thin://node1.example.com> insert into balance (type,amount,currency,asof,id) values ('Current Balance',30000,'INR','2020-04-07 00:00:00.000','1009230183926');
Error: Duplicate key during INSERT [key=SQL_PUBLIC_BALANCE_4791140f_63cb_4663_8c02_58f14073ff0c_KEY [idHash=1321771843, hash=-1614321497, TYPE=Current Balance, ID=1009230183926]] (state=23000,code=4001)
java.sql.SQLException: Duplicate key during INSERT [key=SQL_PUBLIC_BALANCE_4791140f_63cb_4663_8c02_58f14073ff0c_KEY [idHash=1321771843, hash=-1614321497, TYPE=Current Balance, ID=1009230183926]]
Does Ignite support composite key like any other RDBMS? How I can resolve this.
Composite keys are supported by Ignite, and in this case, it looks to be configured corrected with both type and id included in the key.
The exception is expected as well, as both inserts have the same values for type and id columns (Current Balance and 1009230183926 respectively).
Related
I have a web application with multiple instance running all connected to a p-SQL with a table - myTable that have only two columns with one column is having unique key constraint.
This application will receive at least 15K request in a second from multiple instance and my requirement is to avoid the duplicate insertion in the table.
myTable:
CREATE TABLE myTable (
id SERIAL PRIMARY KEY,
myData VARCHAR (50) UNIQUE);
Insert statement:
INSERT INTO myTable (myData) VALUES ('data-1');
My question is if all the instances try to insert same data (assume the above insert statement from all the instances), all at a time to the table will I get only one record inserted and one instance will get inserted success message and all other instance will get a duplicate key error?
I created a training table and data to put in it.
DDL
It`s privacy data so I deleted it
The table is created normally, but the following error occurs from the insert data after the company, that is, when the value is put in the employee data.
error - ORA-02291: integrity constraint (SYSTEM.SYS_C007017) violated - parent key not found
Is there any value I set incorrectly when I created the table?
And does my table fit the conditions?
Which data should be inserted before modification? ..
thank you for reading
my version -> oracle 11g
The primary key of table COMPANY is COMPANY_NAME, for which you have inserted these values:
SAMSUNG
LG
POSCO
KIA
SK
Table EMPLOYEE has a foreign key (city) references company, which means values in EMPLOYEE.CITY must match existing values in COMPANY.COMPANY_NAME.
You are trying to insert 'Soeul' into EMPLOYEE.CITY. Since this does not match any value of COMPANY.COMPANY_NAME, you get the constraint violation.
I'm running Postgres10 on PGAdmin4
To see if my database is out of sync, I'm checking my primary key and primary key sequence.
I'm running this query to check primary key:
MAX(sid) FROM schema_name.table_name; Returns 1032
sid is the primary key
schema_name is the schema where my table is located
table_name is name of the table where the unique constraint is being violated
I'm running this query to check primary key sequence:
SELECT nextval(pg_get_serial_sequence('schema_name.table_name', 'sid')); returns 1042 (current value is 1041).
Referencing this SO: I'm referencing this stack overflow: postgresql duplicate key violates unique constraint
But the post is 9 years old and the solution only checks if the primary key's max is greater than the next value of the sequence (which it isn't in my case).
I have run into issues with a key being out of sync with a sequence when a custom program is inserting records records into a table and taking the last_key_value + 1 while another program is using the sequence nextval to insert into the same table.
This can create duplicate key problems.
I would check to make sure you don't have programs with this conflict.
A better way to fully circumvent this type of problem is to use an IDENTITY type column. Though I dont know if Postgres supports this data type.
I am trying to insert a few values in an existing table, but first it makes nothing and 2nd time it shows me this error message.
My Unique KEY consists of a FK of a higher table and a counter.
If I check my tables there is no entry but it does not accept my UNIQUE Key.
Anybody with some ideas?
My test SQL Code for inserting into the view (same result with table)
INSERT INTO V_BRESZ(BRES_ID_LINKKEY, Maskenkey)
VALUES(29, 60);
For example my error message is:
violation of PRIMARY or UNIQUE KEY constraint "UK_BRESZ" on table
"BRESZ". Problematic key value is ("MASKENKEY" = ' 60',
"BRES_ID_LINKKEY" = 29).
But there is no such entry in my table / view.
I need to be able to insert multiple rows in a table where one of the fields, a foreign key will be included in multiple rows.
Currently when I'm trying to do insert I'm getting this error:
An exception of type 'System.Data.SqlClient.SqlException' occurred in
System.Data.dll but was not handled in user code
Additional information: Cannot insert duplicate key row in object
'dbo.userGroupMembership' with unique index 'IX_userId'. The duplicate
key value is (264673).
Query I'm using:
INSERT INTO userGroupMembership(userId, usergroupId, created, adultAdminAccessLevel)
SELECT [userId], 12, GETDATE(), 0
FROM [dbo].[userGroupMembership]
where usergroupId = #UserGroupId
UserId is the foreign key field.
Any idea if I need to do any configuration change in the table or how can I be able to insert multiple rows with same foreign key?
You have a unique index allowing one row per userID. If you truly want more than one row per userID just drop the unique index.
DROP INDEX dbo.userGroupMembership.IX_userID;