/
Extract tag data

Extract tag data

Machbase provides high-speed tag data extraction, especially for the time range of a specific tag.

Sample Schema


In the following example, we created a TAG table and created two tags as shown below.

For each tag, data from January 1, 2018 to February 10, 2018 were inserted.

create tagdata table TAG (name varchar(20) primary key, time datetime basetime, value double summarized);

insert into tag metadata values ('TAG_0001');
insert into tag metadata values ('TAG_0002');

insert into tag values('TAG_0001', '2018-01-01 01:00:00 000:000:000', 1);
insert into tag values('TAG_0001', '2018-01-02 02:00:00 000:000:000', 2);
insert into tag values('TAG_0001', '2018-01-03 03:00:00 000:000:000', 3);
insert into tag values('TAG_0001', '2018-01-04 04:00:00 000:000:000', 4);
insert into tag values('TAG_0001', '2018-01-05 05:00:00 000:000:000', 5);
insert into tag values('TAG_0001', '2018-01-06 06:00:00 000:000:000', 6);
insert into tag values('TAG_0001', '2018-01-07 07:00:00 000:000:000', 7);
insert into tag values('TAG_0001', '2018-01-08 08:00:00 000:000:000', 8);
insert into tag values('TAG_0001', '2018-01-09 09:00:00 000:000:000', 9);
insert into tag values('TAG_0001', '2018-01-10 10:00:00 000:000:000', 10);

insert into tag values('TAG_0002', '2018-02-01 01:00:00 000:000:000', 11);
insert into tag values('TAG_0002', '2018-02-02 02:00:00 000:000:000', 12);
insert into tag values('TAG_0002', '2018-02-03 03:00:00 000:000:000', 13);
insert into tag values('TAG_0002', '2018-02-04 04:00:00 000:000:000', 14);
insert into tag values('TAG_0002', '2018-02-05 05:00:00 000:000:000', 15);
insert into tag values('TAG_0002', '2018-02-06 06:00:00 000:000:000', 16);
insert into tag values('TAG_0002', '2018-02-07 07:00:00 000:000:000', 17);
insert into tag values('TAG_0002', '2018-02-08 08:00:00 000:000:000', 18);
insert into tag values('TAG_0002', '2018-02-09 09:00:00 000:000:000', 19);
insert into tag values('TAG_0002', '2018-02-10 10:00:00 000:000:000', 20);

목차


Extract all TAG data


Mach> select * from tag;
NAME TIME VALUE 
--------------------------------------------------------------------------------------
TAG_0001 2018-01-01 01:00:00 000:000:000 1 
TAG_0001 2018-01-02 02:00:00 000:000:000 2 
TAG_0001 2018-01-03 03:00:00 000:000:000 3 
TAG_0001 2018-01-04 04:00:00 000:000:000 4 
TAG_0001 2018-01-05 05:00:00 000:000:000 5 
TAG_0001 2018-01-06 06:00:00 000:000:000 6 
TAG_0001 2018-01-07 07:00:00 000:000:000 7 
TAG_0001 2018-01-08 08:00:00 000:000:000 8 
TAG_0001 2018-01-09 09:00:00 000:000:000 9 
TAG_0001 2018-01-10 10:00:00 000:000:000 10 
TAG_0002 2018-02-01 01:00:00 000:000:000 11 
TAG_0002 2018-02-02 02:00:00 000:000:000 12 
TAG_0002 2018-02-03 03:00:00 000:000:000 13 
TAG_0002 2018-02-04 04:00:00 000:000:000 14 
TAG_0002 2018-02-05 05:00:00 000:000:000 15 
TAG_0002 2018-02-06 06:00:00 000:000:000 16 
TAG_0002 2018-02-07 07:00:00 000:000:000 17 
TAG_0002 2018-02-08 08:00:00 000:000:000 18 
TAG_0002 2018-02-09 09:00:00 000:000:000 19 
TAG_0002 2018-02-10 10:00:00 000:000:000 20 
[20] row(s) selected.

If there is no special condition as described above, data can be extracted for each tag arranged in each time order.


Extract data for a specific tag name


Below is an example of data with TAG name TAG_0002.

Mach> select * from tag where name='TAG_0002';
NAME                  TIME                            VALUE                       
--------------------------------------------------------------------------------------
TAG_0002              2018-02-01 01:00:00 000:000:000 11                          
TAG_0002              2018-02-02 02:00:00 000:000:000 12                          
TAG_0002              2018-02-03 03:00:00 000:000:000 13                          
TAG_0002              2018-02-04 04:00:00 000:000:000 14                          
TAG_0002              2018-02-05 05:00:00 000:000:000 15                          
TAG_0002              2018-02-06 06:00:00 000:000:000 16                          
TAG_0002              2018-02-07 07:00:00 000:000:000 17                          
TAG_0002              2018-02-08 08:00:00 000:000:000 18                          
TAG_0002              2018-02-09 09:00:00 000:000:000 19                          
TAG_0002              2018-02-10 10:00:00 000:000:000 20                          
[10] row(s) selected.


Query for time range


The following is a query of a time range for TAG_0002 and receives data.

Mach> select * from tag where name = 'TAG_0002' and time between to_date('2018-02-01') and to_date('2018-02-05');
NAME                  TIME                            VALUE                       
--------------------------------------------------------------------------------------
TAG_0002              2018-02-01 01:00:00 000:000:000 11                          
TAG_0002              2018-02-02 02:00:00 000:000:000 12                          
TAG_0002              2018-02-03 03:00:00 000:000:000 13                          
TAG_0002              2018-02-04 04:00:00 000:000:000 14                          
[4] row(s) selected.

Mach> select * from tag where name = 'TAG_0002' and time > to_date('2018-02-01') and time < to_date('2018-02-05');
NAME                  TIME                            VALUE                       
--------------------------------------------------------------------------------------
TAG_0002              2018-02-01 01:00:00 000:000:000 11                          
TAG_0002              2018-02-02 02:00:00 000:000:000 12                          
TAG_0002              2018-02-03 03:00:00 000:000:000 13                          
TAG_0002              2018-02-04 04:00:00 000:000:000 14                          
[4] row(s) selected.

Time range search for multiple tags


Below is an example of retrieving the same time range data for two or more tags.

If you want to get fast results for a large number of tags at the same time, it is preferable to perform the following type of query.

Mach> select * from tag where name in ('TAG_0002', 'TAG_0001') and time between to_date('2018-01-05') and to_date('2018-02-05');
NAME                  TIME                            VALUE                       
--------------------------------------------------------------------------------------
TAG_0001              2018-01-05 05:00:00 000:000:000 5                           
TAG_0001              2018-01-06 06:00:00 000:000:000 6                           
TAG_0001              2018-01-07 07:00:00 000:000:000 7                           
TAG_0001              2018-01-08 08:00:00 000:000:000 8                           
TAG_0001              2018-01-09 09:00:00 000:000:000 9                           
TAG_0001              2018-01-10 10:00:00 000:000:000 10                          
TAG_0002              2018-02-01 01:00:00 000:000:000 11                          
TAG_0002              2018-02-02 02:00:00 000:000:000 12                          
TAG_0002              2018-02-03 03:00:00 000:000:000 13                          
TAG_0002              2018-02-04 04:00:00 000:000:000 14                          
[10] row(s) selected.


Search data over a certain value


The conditions for the tag value can also be given as follows.

Filtering was performed for those values greater than 12 and less than 15 among the values of TAG_0002.

Mach> select * from tag where name = 'TAG_0002' and value > 12 and value < 15 and time between to_date('2018-02-01') and to_date('2018-02-05');
NAME                  TIME                            VALUE                       
--------------------------------------------------------------------------------------
TAG_0002              2018-02-03 03:00:00 000:000:000 13                          
TAG_0002              2018-02-04 04:00:00 000:000:000 14                          
[2] row(s) selected.


Related content