How to copy data including the meta data from a data table to another data table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
How to copy data including the meta data from a data table to another data table
I've tried duplicating the data table entity in composer, but it did not copy the data over. If I use the service AddDataTableEntries, to import the data as an infotable, it does not copy the meta data. Is there a way to copy data including the meta data from a data table to another data table? I need a data table with the same data, but with a different data table name.
- Labels:
-
Coding
- Tags:
- Data Table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
What metadata are you referring to here?
You can check the article CS330382 at https://www.ptc.com/en/support/article/cs330382
This article is for Stream, it should work for Datatable if you replace GetStreamEntriesWithData with QueryDataTableEntries of Datatable and AddStreamEntry with AddDataTableEntry of Datatable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you for sharing the article. I will give that a try. By meta data, I meant timestamp, source, tags, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I tried it, but I noticed that AddDataTableEntry doesn't have timestamp as a parameter. timestamp is a critical piece for me. I need to retain the timestamps from the entries in the source data table.
let id = Things["DataTableName"].AddDataTableEntry({
sourceType: undefined /* STRING */,
values: undefined /* INFOTABLE */,
location: undefined /* LOCATION */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hello @Willie
This can be done by using SQL database query. You can create a new datatable and also create a datatable with similar name in composer to be a duplicate of your source datatable.
Hope this helps! Pls let me know if you face any further challenges.
Regards,
Bhawna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I found the following Postgres queries to work for this task:
Copying:
INSERT INTO data_table (entity_id, entity_key, field_values, location, source_id, source_type, tags, "time", full_text) SELECT 'TargetDataTableName' AS entity_id, entity_key, field_values, location, source_id, source_type, tags, "time", full_text FROM data_table where entity_id='SourceDataTableName';
Verifying:
select * from data_table where entity_id= 'TargetDataTableName';
