cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Overlapping datashape and inherent datatable fields

Michail
9-Granite

Overlapping datashape and inherent datatable fields

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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,

View solution in original post

3 REPLIES 3

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,

Top Tags