Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Section


Column
width1024px

INSERT


insert_stmt:

insert_column_list:

value_list:


set_list:


Code Block
insert_stmt ::= 'INSERT INTO' table_name ( '(' insert_column_list ')' )? 'METADATA'? 'VALUES' '(' value_list ')' ( 'ON DUPLICATE KEY UPDATE' ( 'SET' set_list )? )?
insert_column_list ::= column_name ( ',' column_name )*
value_list ::= value ( ',' value )*
set_list ::= column_name '=' value ( ',' column_name '=' value )*


Code Block
create table test (number int,name varchar(20));
Created successfully.
insert into test values (1,"test");
1 row(s) inserted.
insert into test(name,number) values ("test",2);
1 row(s) inserted.

특정 테이블에 값을 입력하는 구문이다. 한 가지 특이한 점은 Column_List에서 지정되지 않은 컬럼에는 모두 NULL 값으로 채워진다는 것이다. 이는 입력의 편의성과 저장 공간의 효율화를 위해 채택된 로그 파일의 특성을 고려한 정책이다.

METADATA는 tag table에만 사용이 가능하다.

Column


목차

This is the syntax for entering values ​​into a specific table. One unusual thing is that columns not specified in Column_List are all filled with NULL values. This is a policy considering the characteristics of log files adopted for convenience of input and efficiency of storage space.
METADATA is only available for tag tables.


Column

Index


Table of Contents
maxLevel3
indent30px
exclude목차
classtoc


...

INSERT ON DUPLICATE KEY UPDATE

마크베이스는, 흔히 알려진 UPSERT 기능과 유사한 구문을 지원한다.

기본 키가 지정된 Lookup/Volatile 테이블에 값을 입력할 때 사용할 수 있는 특수 구문으로, 기본 키 값이 중복되는 데이터가 이미 테이블에 존재하는 경우에는 기존 데이터의 값이 변경된다.
물론, 키 값이 중복되는 데이터가 존재하지 않는 경우에는 새로운 데이터로 삽입된다.

이 구문을 사용하기 위해서, 휘발성 테이블에 기본 키가 지정되어 있어야 한다.

삽입되는 데이터의 컬럼 값과 갱신되는 데이터의 컬럼 값을 다르게 하고자 하는 경우, 또는 삽입되는 데이터의 컬럼 값이 아닌 다른 컬럼 값을 갱신하고자 하는 경우에는 SET 절을 추가로 입력할 수 있다.

...

SET 절에는 '컬럼=값'으로 구성되며, 각각을 콤마로 구분해야 한다.

...

Machbase supports syntax similar to the commonly known UPSERT function.

A special syntax that can be used when entering a value into a Lookup/Volatile table with a primary key specified. If the table already contains data with a duplicate primary key value, the value of the existing data is changed. 
Of course, when there is no duplicated key value data, it is inserted as new data.

To use this syntax, the primary key must be specified in the volatile table.

If the column value of the inserted data is different from the column value of the updated data, or if it is desired to update a column value other than the column value of the inserted data, the SET clause can be further input.

  • The SET clause consists of 'column = value', each separated by a comma.

  • You must not change the default key value in the SET clause.

INSERT SELECT

...

insert_select_stmt:

...

Code Block
insert_select_stmt ::= 'INSERT INTO' table_name ( '(' insert_column_list ')' )? select_stmt

특정 table에 대해서 SELECT 문의 수행 결과를 삽입하는 문장이다. 기본적으로는 다른 DBMS와 유사하지만 다음의 차이점이 있다.

...

_ARRIVAL_TIME 컬럼 값은 select 및 INSERT 컬럼 리스트에서 지정되지 않으면 INSERT SELECT 문이 수행되는 시점의 시간 값으로 입력된다.

...

VARCHAR 타입의 컬럼에 대해서 삽입되는 입력값이 컬럼의 최대 길이보다 큰 경우, 오류를 발생시키지 않고 해당 컬럼의 최대 길이만큼 잘라서 입력된다.

...

형 변환이 가능한 경우(숫자형->숫자형)에는 입력되는 컬럼 값에 맞게 삽입된다.

...

수행 도중 오류가 발생한 경우 ROLLBACK되지 않는다.

...

This statement inserts the result of the SELECT statement on a specific table. In basic, it is similar to other DBMSs, but with the following differences.

  1. The _ARRIVAL_TIME column value is entered as the time value at the time the INSERT SELECT statement is executed unless specified in the select and INSERT column lists.

  2. If the input value to be inserted for a VARCHAR type column is greater than the maximum length of the column, the maximum length of the corresponding column is entered without error.

  3. If type conversion is possible (numeric -> numeric), it is inserted according to the input column value.

  4. ROLLBACK does not occur if an error occurs during execution.

  5. If you insert a value in the _ARRIVAL_TIME column, the new value will not be entered if it has a time before the existing value.

Code Block
sql
sql
create table t1 (i1 integer, i2 varchar(60), i3 varchar(5));
Created successfully.

insert into t1 values (1, 'a', 'ddd' );
1 row(s) inserted.
insert into t1 values (2, 'kkkkkkkkkkkkkkkkkkkkk', 'c');
1 row(s) inserted.

insert into t1 select * from t1;
2 row(s) inserted.
create table t2 (i1 integer, i2 varchar(60), i3 varchar(5));

insert into t2 (_arrival_time, i1, i2, i3) select _arrival_time, * from t1;
4 row(s) inserted.


UPDATE

...

Info

This function is available from 5.5 부터 제공되는 기능입니다.


Image Removedupdate_stmt:

Image Added

update_expr_list:

...

Code Block
update_stmt ::= 'UPDATE' table_name ( 'METADATA' )? 'SET' update_expr_list 'WHERE' primary_key_column '=' value
update_expr_list ::= update_expr ( ',' update_expr)*
update_expr ::= column '=' value

INSERT ON DUPLICATE KEY UPDATE 를 통한 UPSERT 가 아닌, UPDATE 구문도 제공된다.역시, 기본 키 (Primary Key) 가 지정된 Lookup/Volatile 테이블에 값을 입력할 때 사용할 수 있다. WHERE 절에는 기본 키의 일치 조건식을 작성해야 한다UPDATE syntax is also provided, rather than UPSERT via a KEY UPDATE.
You can also use the Primary Key to enter values ​​into the specified Lookup/Volatile table. In the WHERE clause, you must create a matching predicate for the primary key.

UPDATE METADATA

Only for the TAGDATA 테이블에 한해서, 메타데이터를 업데이트 하고자 할 때 사용한다table, when you want to update the metadata.

Code Block
sql
sql
UPDATE TAG METADATA SET ...


Note

TAGDATA 테이블의 메타데이터는 The metadata of the TAGDATA table can not be entered/modified through INSERT ON DUPLICATE KEY UPDATE 를 통해 입력/수정할 수 없다.

DELETE

...

delete_stmt:

time_unit:


Code Block
delete_stmt ::= 'DELETE FROM' table_name ( 'OLDEST' number 'ROWS' | 'EXCEPT' number ( 'ROWS' | time_unit ) | 'BEFORE' datetime_expression )? 'NO WAIT'?
time_unit ::= 'DURATION' number time_unit ( ( 'BEFORE' | 'AFTER' ) number time_unit )?

마크베이스에서의 DELETE BEFORE 구문은 로그 테이블, Tag 테이블, Rollup table에 대해서 수행 가능하다. 중간의 임의 위치에 있는 데이터를 삭제할 수 없으며, 임의의 위치부터 연속적으로 마지막(가장 오래된 로그) 레코드까지 지울 수 있도록 구현되었다.

이는 로그 데이터의 특성을 살린 정책으로서 한번 입력되면 수정이 없고, 공간 확보를 위해 파일을 삭제하는 행위를 DB 형식으로 표현한 것이다.

DURATION, OLDEST, EXCEPT 구문은 TAG 및 Rollup 테이블에 대해서는 사용할 수 없다The DELETE statement in Machbase can be performed on the log table. In addition, it is not possible to delete data in an arbitrary position in the middle, and it is possible to erase consecutively from the arbitrary position to the last (oldest log) record.

This is a policy that takes advantage of the characteristics of log data. It is a DB format representation of the act of deleting a file in order to secure space when it is entered once.

The syntax of DURATION, OLDEST, and EXCEPT cannot be used for TAG and Rollup tables.

Code Block
sql
sql
-- 모두Delete 삭제하라all.
DELETE FROM devices;

-- 가장Delete 오래된oldest 마지막last N건을N 삭제하라rows.
DELETE FROM devices OLDEST N ROWS;

-- Delete 최근all N건을except 제외하고recent 모두N 삭제하라rows.
DELETE FROM devices EXCEPT N ROWS;

-- 지금부터 N일치를 남기고 모두 삭제하라 Delete all except N matches from now on.
DELETE FROM devices EXCEPT N DAY;

-- Delete 2014년all 6월data 1일from 이전의before 데이터를June 모두1, 삭제하라2014.
DELETE FROM devices BEFORE TO_DATE('2014-06-01', 'YYYY-MM-DD');

-- Delete tag data from 데이터의before 시간June 기준1, 삭제2014.
DELETE FROM tag BEFORE TO_DATE('2014-06-01', 'YYYY-MM-DD');

-- Delete tag rollup data 데이터의from before 시간June 기준1, 삭제2014.
DELETE FROM tag ROLLUP BEFORE TO_DATE('2014-06-01', 'YYYY-MM-DD');

...

Code Block
sql
sql
create volatile table t1 (i1 int primary key, i2 int);
Created successfully.
insert into t1 values (2,2);
1 row(s) inserted.
delete from t1 where i1 = 2;
1 row(s) deleted.

휘발성 테이블에 대해서만 수행 가능한 구문으로, WHERE 절에 작성된 조건에 일치하는 레코드만 삭제할 수 있다.

  • 기본 키가 지정된 휘발성 테이블에 대해서만 수행 가능하다.

  • WHERE 절에는 (기본 키 컬럼) = (값) 의 조건만 허용되며, 다른 조건과 함께 작성할 수 없다.

  • 기본 키 컬럼이 아닌 다른 컬럼을 조건에 사용할 수 없다You can only delete records that match the conditions created in the WHERE clause, which can only be performed on volatile tables.

  • The primary key can only be performed on the specified volatile table.

  • The WHERE clause allows only conditions of (primary key column) = (value), and can not be created with other conditions.

  • You can not use a column other than the primary key column in the condition.

delete_from_tag_where_stmt:

...

Code Block
sql
sql
delete_from_tag_where_stmt ::= 'DELETE FROM' table_name 'WHERE' tag_name '=' value ( and tag_time '<' datetime_expression  )?

Tag 테이블은 아래와 같이 2가지 방식의 삭제쿼리가, 삭제 쿼리가 추가적으로 지원된다.

  • Tag name 기준 삭제
  • Tag name과 Tag time 기준 삭제

...