태그 데이터의 삭제

태그 데이터 삭제 제약 사항

마크베이스는 태그 테이블 전체에 대해서 특정 시간 이전의 전체 데이터에 대한 삭제만을 지원한다.

불가능한 태그 데이터 삭제 조건

  • 특정 시간 범위의 데이터를 삭제

가능한 태그 데이터 삭제 조건

  • 특정 태그 아이디 삭제
  • 특정 태그 아이디의 특정 시간 이전의 데이터 삭제
  • 특정 태그 아이디의 특정 시간 범위 데이터 삭제
  • 특정 시간 이전의 전체 태그에 대한 삭제
  • 전체 삭제

DELETE 구문 수행

특정 태그 아이디 삭제

특정 태그 아이디를 지정하면 해당 태그는 모두 삭제한다.

DELETE FROM TAG WHERE NAME = 'TAG-ID';
## 현재 데이터
Mach> select * from tag;
NAME                  TIME                            VALUE
--------------------------------------------------------------------------------------
TAG_0001              2024-01-01 10:00:00 000:000:000 1
TAG_0001              2024-01-01 10:00:01 000:000:000 1
TAG_0001              2024-01-01 10:00:04 000:000:000 1
TAG_0001              2024-01-01 10:00:06 000:000:000 1
TAG_0001              2024-01-01 10:00:09 000:000:000 1
TAG_0001              2024-01-01 10:00:10 000:000:000 1
TAG_0002              2024-01-01 10:00:02 000:000:000 1
TAG_0002              2024-01-01 10:00:03 000:000:000 1
TAG_0002              2024-01-01 10:00:05 000:000:000 1
TAG_0002              2024-01-01 10:00:07 000:000:000 1
TAG_0002              2024-01-01 10:00:08 000:000:000 1
[11] row(s) selected.

Mach> delete from tag where name = 'TAG_0002';
5 row(s) deleted.

Mach> select * from tag;
NAME                  TIME                            VALUE
--------------------------------------------------------------------------------------
TAG_0001              2024-01-01 10:00:00 000:000:000 1
TAG_0001              2024-01-01 10:00:01 000:000:000 1
TAG_0001              2024-01-01 10:00:04 000:000:000 1
TAG_0001              2024-01-01 10:00:06 000:000:000 1
TAG_0001              2024-01-01 10:00:09 000:000:000 1
TAG_0001              2024-01-01 10:00:10 000:000:000 1
[6] row(s) selected.

특정 태그 아이디의 특정 시간 이전의 데이터 삭제

특정 태그 아이디와 특정 시간을 지정하면 해당 태그의 특정 시간 이전 데이터를 삭제한다.

DELETE FROM TAG WHERE NAME = 'TAG-ID' AND TIME <= 'Time-string';
## 현재 데이터
Mach> select * from tag;
NAME                  TIME                            VALUE
--------------------------------------------------------------------------------------
TAG_0001              2024-01-01 10:00:00 000:000:000 1
TAG_0001              2024-01-01 10:00:01 000:000:000 1
TAG_0001              2024-01-01 10:00:04 000:000:000 1
TAG_0001              2024-01-01 10:00:06 000:000:000 1
TAG_0001              2024-01-01 10:00:09 000:000:000 1
TAG_0001              2024-01-01 10:00:10 000:000:000 1
TAG_0002              2024-01-01 10:00:02 000:000:000 1
TAG_0002              2024-01-01 10:00:03 000:000:000 1
TAG_0002              2024-01-01 10:00:05 000:000:000 1
TAG_0002              2024-01-01 10:00:07 000:000:000 1
TAG_0002              2024-01-01 10:00:08 000:000:000 1
[11] row(s) selected.

Mach> delete from tag where name = 'TAG_0002' and time <= '2024-01-01 10:00:05';
3 row(s) deleted.

Mach> select * from tag;
NAME                  TIME                            VALUE
--------------------------------------------------------------------------------------
TAG_0001              2024-01-01 10:00:00 000:000:000 1
TAG_0001              2024-01-01 10:00:01 000:000:000 1
TAG_0001              2024-01-01 10:00:04 000:000:000 1
TAG_0001              2024-01-01 10:00:06 000:000:000 1
TAG_0001              2024-01-01 10:00:09 000:000:000 1
TAG_0001              2024-01-01 10:00:10 000:000:000 1
TAG_0002              2024-01-01 10:00:07 000:000:000 1
TAG_0002              2024-01-01 10:00:08 000:000:000 1
[8] row(s) selected.

특정 태그 아이디의 특정 시간 범위 데이터 삭제

특정 태그 아이디와 특정 시간 범위를 지정하면 해당 태그의 해당 시간 시간 범위 데이터를 삭제한다.

DELETE FROM TAG WHERE NAME = 'TAG-ID' AND TIME >= 'Time-string' AND TIME <= 'Time-string';
## 현재 데이터
Mach> select * from tag;
NAME                  TIME                            VALUE
--------------------------------------------------------------------------------------
TAG_0001              2024-01-01 10:00:00 000:000:000 1
TAG_0001              2024-01-01 10:00:01 000:000:000 1
TAG_0001              2024-01-01 10:00:04 000:000:000 1
TAG_0001              2024-01-01 10:00:06 000:000:000 1
TAG_0001              2024-01-01 10:00:09 000:000:000 1
TAG_0001              2024-01-01 10:00:10 000:000:000 1
TAG_0002              2024-01-01 10:00:02 000:000:000 1
TAG_0002              2024-01-01 10:00:03 000:000:000 1
TAG_0002              2024-01-01 10:00:05 000:000:000 1
TAG_0002              2024-01-01 10:00:07 000:000:000 1
TAG_0002              2024-01-01 10:00:08 000:000:000 1
[11] row(s) selected.

Mach> delete from tag where name = 'TAG_0002' and time >= '2024-01-01 10:00:04' and time <= '2024-01-01 10:00:08';
3 row(s) deleted.

Mach> select * from tag;
NAME                  TIME                            VALUE
--------------------------------------------------------------------------------------
TAG_0001              2024-01-01 10:00:00 000:000:000 1
TAG_0001              2024-01-01 10:00:01 000:000:000 1
TAG_0001              2024-01-01 10:00:04 000:000:000 1
TAG_0001              2024-01-01 10:00:06 000:000:000 1
TAG_0001              2024-01-01 10:00:09 000:000:000 1
TAG_0001              2024-01-01 10:00:10 000:000:000 1
TAG_0002              2024-01-01 10:00:02 000:000:000 1
TAG_0002              2024-01-01 10:00:03 000:000:000 1
[8] row(s) selected.

특정 시간 이전의 전체 태그에 대한 삭제

BEFORE 구문의 시간을 지정하면 그 시간 이전의 태그는 모두 삭제한다.

DELETE FROM TAG BEFORE TO_DATE('Time-string');
## 현재 데이터
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.
 
Mach> delete from tag before to_date('2018-02-01');
10 row(s) deleted.
 
Mach> select * from tag;
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.

특정 시간 범위의 태그에 대한 삭제

DELETE FROM TAG BEFORE TO_DATE('Time-string');
## 현재 데이터
Mach> select * from tag;
NAME                  TIME                            VALUE
--------------------------------------------------------------------------------------
TAG_0001              2024-01-01 10:00:00 000:000:000 1
TAG_0001              2024-01-01 10:00:01 000:000:000 1
TAG_0001              2024-01-01 10:00:04 000:000:000 1
TAG_0001              2024-01-01 10:00:06 000:000:000 1
TAG_0001              2024-01-01 10:00:09 000:000:000 1
TAG_0001              2024-01-01 10:00:10 000:000:000 1
TAG_0002              2024-01-01 10:00:02 000:000:000 1
TAG_0002              2024-01-01 10:00:03 000:000:000 1
TAG_0002              2024-01-01 10:00:05 000:000:000 1
TAG_0002              2024-01-01 10:00:07 000:000:000 1
TAG_0002              2024-01-01 10:00:08 000:000:000 1
[11] row(s) selected.

전체 삭제

아무 조건이 없는 경우 전체 데이터가 삭제된다.

Mach> delete from tag;
10 row(s) deleted.
 
Mach> select * from tag;
NAME TIME VALUE
--------------------------------------------------------------------------------------
[0] row(s) selected.

ROLLUP 데이터의 삭제

DELETE FROM TAG ROLLUP BEFORE TO_DATE('Time-string');

위에서 BEFORE 구문의 시간을 지정하면 그 시간 이전의 시, 분, 초 ROLLUP 데이터가 삭제된다.

만일 BEFORE 구문을 지정하지 않는 경우에는 ROLLUP의 모든 데이터를 삭제한다.

최근 업데이트