What is the best practice in BaseX to implement a uniqueness constraint similar to a RDBMS? Given a database, a path to the documents, an optional RegEx expression on files in the path, and one or more XPaths to the constraint elements/attributes. Can I create an index of this nature? Can the index not allow duplicates?
Hi E. Wray,
What is the best practice in BaseX to implement a uniqueness constraint similar to a RDBMS?
Using UUIDs has become our favorite solution. An alternative is to assign an incrementing integer, and e.g. store the highest assigned value in the root node. If you want to assign arbitrary values, you’ll need to check if the value has already been assigned:
let $id := 'sjdhsj' return if(//item[@id = $id])) then ( error( (), "ID is not unique: " || $id) ) else ( ... )
If your database has an up-to-date attribute index, this should be pretty fast.
Christian
We are already using UUIDs for file names. However we want, for example, guaranteed uniqueness across text names contained in elements within documents of a collection.
On Jan 9, 2016, at 12:52 PM, "Christian Grün" christian.gruen@gmail.com wrote:
Hi E. Wray,
What is the best practice in BaseX to implement a uniqueness constraint similar to a RDBMS?
Using UUIDs has become our favorite solution. An alternative is to assign an incrementing integer, and e.g. store the highest assigned value in the root node. If you want to assign arbitrary values, you’ll need to check if the value has already been assigned:
let $id := 'sjdhsj' return if(//item[@id = $id])) then ( error( (), "ID is not unique: " || $id) ) else ( ... )
If your database has an up-to-date attribute index, this should be pretty fast.
Christian
We are already using UUIDs for file names. However we want, for example, guaranteed uniqueness across text names contained in elements within documents of a collection.
I am not sure how "text names contained in elements" will be represented in your data. If it’s stored in text or attribute nodes, just try the query I’ve sent.
On Jan 9, 2016, at 12:52 PM, "Christian Grün" christian.gruen@gmail.com wrote:
Hi E. Wray,
What is the best practice in BaseX to implement a uniqueness constraint similar to a RDBMS?
Using UUIDs has become our favorite solution. An alternative is to assign an incrementing integer, and e.g. store the highest assigned value in the root node. If you want to assign arbitrary values, you’ll need to check if the value has already been assigned:
let $id := 'sjdhsj' return if(//item[@id = $id])) then ( error( (), "ID is not unique: " || $id) ) else ( ... )
If your database has an up-to-date attribute index, this should be pretty fast.
Christian
basex-talk@mailman.uni-konstanz.de