Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/What is the equivalent in Daml to DB sequences?Forum ↗

What is the equivalent in Daml to DB sequences?

App Development4 posts175 viewsLast activity May 2022
CO
cohen.avrahamOP
May 2022

G-d willing

Hello,
I need each instance of a specific contract to have a unique id. Is there anything in Daml that implement it?
In databases we have auto-incremented sequences… I was thinking, is there something similar in Daml?

GA
Gary_Verhaegen
May 2022

Hi @cohen.avraham,

A Daml application is, by nature, a distributed application. That means you cannot assume a “global” point of view, which in this case in turns means you cannot, in general, guarantee that all contracts of a given template have a different (much less “auto-increment”) value for a given field.

If you trust all of the parties involved to “play by the rules”, a possible solution would be to have a Text field in your contract that gets populated by a UUID generated client-side. The probability of collision on UUIDs is low enough that this should work out to unique IDs for all practical intents and purposes, as long as there is no deliberate fudging.

ST
Stephen
May 2022

The contract ID is unique; perhaps you can exploit this.

CO
cohen.avraham
May 2022

Hi @Stephen, for my use case it’s not, but thanks anyway

← Back to Discussions