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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

How to copy data including the meta data from a data table to another data table

Willie
16-Pearl

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.

5 REPLIES 5
Jimwang
15-Moonstone
(To:Willie)

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

 

Willie
16-Pearl
(To:Jimwang)

@Jimwang 

Thank you for sharing the article.  I will give that a try.    By meta data, I meant timestamp, source, tags, etc.

Willie
16-Pearl
(To:Jimwang)

@Jimwang 

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 */
});

 

bchaudhary
17-Peridot
(To:Willie)

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

 

 

@bchaudhary 

 

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';
Top Tags