Written by

Question Denham Pole · Feb 22, 2023

Using UUID as primary key

Hello,

Comming back to Cache after some long gap. Is it possible to use UUID  as primary key while creing a Persistant class (Not using the default numerical ID)?

and creating the relationships also using UUID?

Product version: IRIS 2022.2

Comments

Dmitry Maslennikov · Feb 22, 2023

You can use whatever you want, just remember about some caveats, like issue with bitslice/bitmap indexes, which requires numerical ID

I would recommend using just a Unique Index for the UUID field and use it, it should cover most of the needs.

0
Denham Pole  Feb 22, 2023 to Dmitry Maslennikov

What is the datatype for UUID? 

id this one HS.FHIR.vSTU3.Model.Datatype.Uuid?

How we can autogenerate UUID when creating an object?

##class(%SYS.System).InstanceGUID()

This function returning a same UUID!!!

0
Enrico Parisi · Feb 23, 2023

Personally I'd rather use a default numeric ID and if needed an additional UUID/GUID unique property.

To implement what you asked you can use something like:

Class My.TestClass Extends%Persistent
{
Property PrimaryUUID As%String [ InitialExpression = {$system.Util.CreateGUID()} ];Property MyOtherData As%String;

Index PrimaryUUIDIndex On PrimaryUUID [ IdKey, Unique ];
}

In this way the primary key (PrimaryUUID) is automatically assigned, no need to set it manually, in SQL is mapped as ID (as well as PrimaryUUID).

Enrico

0
Denham Pole  Feb 23, 2023 to Enrico Parisi

Thank you very much. desiging a system where data can be merged from differant local DBs. by having UUID there wont be any conflict in primary keys when merging!

0