Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
In order to make "timestamp" inherent datashape field as a primary key, I created a data-shape with the same field set as a primary key. As a result, the datatable has got one "timestamp" field as a primary key. It solves my problem, but is it ok to do that? Can it cause any problems? Thanks.
Solved! Go to Solution.
You can implement an autoincrement easily ( with a property that holds last entry created ) or better ( for concurrency purposes, but it occupies more space ) use GUID value as pk.
You have a helper function called generateGUID() which will generate a "unique" value for each entry.
Best Regards,
Why don't you use a Stream instead of a DataTable, if PK it's timestamp, then it's time series data and Stream it's better suited than DataTables ( of course if you don't need Synchronous writes, on which case you are forced to use DataTables ).
On the case that you need Synchronous writes, then you will need DataTables and on this case I would never add a column named timestamp ( neither location, sourceType, tags or source ) as thouse are already on any DataTable entry by default. If you want a column with a timestamp as pk, just name it different, it's totally ok ( but remember that you may have more than one entry at the same millisecond... on which case it invalidates it from using as PK ).
Best Regards,.
Carles Coll, thank you for your response. The datatable supposed to save scaling values for different properties, users, things, etc. It must be editable by multiple users (adding, removing rows). The datatable seemed like a natural choice. But that comes with two challenges. First, whatever field I choose as a PK, I need to make sure that each new PK entry is unique. "userName + timestamp.toString()" could potentially solve it. Although slim, but there is a chance that the entry may be created at the same time (down to millisecond).
My solution was to introduce a flag property which indicates when the datatable is use. If it is in use, a service can wait a random number (1-10) of milliseconds and try again. I'd be grateful if you could share your thoughts on that.
You can implement an autoincrement easily ( with a property that holds last entry created ) or better ( for concurrency purposes, but it occupies more space ) use GUID value as pk.
You have a helper function called generateGUID() which will generate a "unique" value for each entry.
Best Regards,