Versions Compared

Key

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

...

Data Insert

...

The data insert of the volatile table is as follows.

Code Block
languagesql
Mach> create volatile table vtable (id integer, name varchar(20));
Created successfully.
Mach> insert into vtable values(1, 'west device');
1 row(s) inserted.
Mach> insert into vtable values(2, 'east device');
1 row(s) inserted.
Mach> insert into vtable values(3, 'north device');
1 row(s) inserted.
Mach> insert into vtable values(4, 'south device');
1 row(s) inserted.

...

Data Append

...

It is a fast real-time data input API provided by Machbase.

C, C++, C#, Java, Python, PHP, Javascript 를 이용하여 입력할 수 있다are available for append.

Code Block
Mach> create volatile table vtable (id integer, value double);

...

Code Block
SQL_APPEND_PARAM sParam[2];
for(int i=0; i<10000; i++)
{
	sParam[0].mInteger  = i;
	sParam[1].mDouble   = i;
	SQLAppendDataV2(stmt, sParam) != SQL_SUCCESS)
}

For the Cluster Edition의 경우 Append 입력은 Leader Broker에서 수행해야 한다.

세부 내용은 SDK 가이드를 참고한다.

데이터 갱신

휘발성 테이블의 데이터 입력 시, ON DUPLICATE KEY UPDATE 절을 사용해 중복된 기본 키 값을 가진 데이터의 갱신을 할 수 있다.

삽입할 데이터 값으로 갱신

INSERT 구문에서 삽입할 데이터를 지정했지만, 삽입 데이터의 기본 키 값과 일치하는 다른 데이터가 존재하는 경우에는 INSERT 구문이 실패하게 되고 해당 데이터는 삽입되지 않는다. 삽입 데이터의 기본 키 값과 일치하는 다른 데이터가 존재하는 경우에, 삽입이 아닌 해당 데이터를 갱신하고자 하는 경우에는 ON DUPLICATE KEY UPDATE 절을 추가할 수 있다.

  • 기본 키 중복 데이터가 존재하지 않는 경우, 삽입할 데이터 내용이 그대로 삽입된다.

  • 기본 키 중복 데이터가 존재하는 경우, 삽입할 데이터 내용으로 기존의 데이터가 갱신된다.

이 기능을 사용하기 위한 제약 조건은 다음과 같다.

...

휘발성 테이블에 기본 키가 지정되어 있어야 한다.

...

Edition Append, must be done by Leader Broker.

Details are in SDK guide.

Data Update

When inputting data in a volatile table, data with duplicate primary key values ​​can be updated using the ON DUPLICATE KEY UPDATE clause.

Update Data Value to be Inserted

If the INSERT statement specifies data to be inserted, but there is other data that matches the primary key value of the insert data, the INSERT statement fails and the corresponding data is not inserted. If there is another data that matches the primary key value of the insertion data, and if you wish to update the corresponding data instead of insertion, a  ON DUPLICATE KEY UPDATE clause can be added.

  • If there is no duplicate primary key data, the contents of the data to be inserted are inserted as is.

  • If there is duplicate primary key data, the existing data is updated with the contents of the data to be inserted.

The constraints for using this function are as follows.

  • The primary key must be specified in the volatile table.

  • The value to be inserted must include the primary key value.


Code Block
languagesql
Mach> create volatile table vtable (id integer primary key, direction varchar(10), refcnt integer);
Created successfully.
Mach> insert into vtable values(1, 'west', 0);
1 row(s) inserted.
Mach> insert into vtable values(2, 'east', 0);
1 row(s) inserted.
Mach> select * from vtable;
ID          DIRECTION   REFCNT      
----------------------------------------
1           west       0           
2           east        0           
[2] row(s) selected.

Mach> insert into vtable values(1, 'south', 0);
[ERR-01418 : The key already exists in the unique index.]
Mach> insert into vtable values(1, 'south', 0) on duplicate key update;
1 row(s) inserted.

Mach> select * from vtable;
ID          DIRECTION   REFCNT      
----------------------------------------
1           south        0           
2           east        0           
[2] row(s) selected.

갱신할 데이터 값을 지정

...


Specify Data Value to be Updated

Similar to above, but if you need to update to a different column value than the data value to be inserted, it can be specified through the ON DUPLICATE KEY UPDATE SET 절을 통해 지정할 수 있다. SET 절 아래에 갱신할 데이터 값을 지정할 수 있다.

  • 기본 키 중복 데이터가 존재하지 않는 경우, 삽입 데이터 내용이 그대로 삽입된다.

  • 기본 키 중복 데이터가 존재하는 경우, SET 절에 명시된 갱신 데이터만으로 기존의 데이터가 갱신된다.

...

기본 키 값을 갱신할 데이터 값으로 지정할 수 없다.

...

 clause. The data value to be updated can be specified under the SET clause.

  • If the primary key duplication data does not exist, the contents of the embedded data are inserted as it is.

  • If there is duplicate primary key data, the existing data is updated only with the update data specified in the SET clause.

  • The primary key value can not be specified as the data value to be updated.

  • The values ​​of the columns not specified in the SET clause are not updated.



Code Block
languagesql
Mach> create volatile table vtable (id integer primary key, direction varchar(10), refcnt integer);
Created successfully.
Mach> insert into vtable values(1, 'west', 0);
1 row(s) inserted.
Mach> insert into vtable values(2, 'east', 0);
1 row(s) inserted.
Mach> select * from vtable;
ID          DIRECTION   REFCNT      
----------------------------------------
1           west        0           
2           east        0           
[2] row(s) selected.

Mach> insert into vtable values(1, 'west', 0) on duplicate key update set refcnt = 1;
1 row(s) inserted.

Mach> select * from vtable;
ID          DIRECTION   REFCNT      
----------------------------------------
1           west        1           
2           east        0           
[2] row(s) selected.

...