Unity Catalog Primary key column taking duplicates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2023 11:41 PM
I have Updated a Hive Meta Store from a Unity Catalog. I have setup Primary keys on the table. When I try to insert duplicates its succeeding Inserts and seems like PK is not working. Anyone else seeing such behaviour ?
- Labels:
-
Unity Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 09:38 AM
Hi, When you say PK is not working, is there any error surfaced?
Please tag @Debayan with your next comment so that I will get notified. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 10:03 AM
@Debayan Mukherjee Im able to insert the same record where we have Primary key setup on the table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 10:13 AM
-----------------
ALTER TABLE ccietlfindev.finsilver.companyperiods ALTER COLUMN iCompanyId SET NOT NULL;
ALTER TABLE ccietlfindev.finsilver.companyperiods ALTER COLUMN iPeriodId SET NOT NULL
ALTER TABLE ccietlfindev.finsilver.companyperiods ADD CONSTRAINT companyperiods_pk PRIMARY KEY(iCompanyId,iPeriodId);
select iCompanyId,iPeriodId, count(1) from ccietlfindev.finsilver.companyperiods
group by iCompanyId,iPeriodId
having count(1) > 1
insert into table ccietlfindev.finsilver.companyperiods
values ('1','182','1996-08-31 23:59:59.998','Aug 1998','1996-08-31 00:00:00.000','C','2023-05-11 15:01:43.707')
Select * from ccietlfindev.finsilver.companyperiods
where iCompanyId = '1' and iPeriodId='182'
delete from ccietlfindev.finsilver.companyperiods
where iCompanyId = '1' and iPeriodId='182' and PeriodDesc='Aug 1997'
Select * from companyperiods
In the case when I run count after the second record insert, I see 2 records instead of just one and should have failed saying "you are trying to insert duplicate records where there is a primary key setup"
@Debayan Mukherjee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2023 06:25 AM
@Debayan Mukherjee Any info on the above plz ??

