Versions Compared

Key

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

...

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

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

...

The Tag table additionally supports two types of deletion queries as follows.

  • Delete by tag name
  • Delete by tag name and tag time
Code Block
languagesql
-- Delete by tag name 기준 삭제
DELETE FROM tag where tag_name = 'my_tag_2021'

-- Delete by tag name and tag time 기준
삭제
DELETE FROM tag where tag_name = 'my_tag_2021' and tag_time < TO_DATE('2021-07-01', 'YYYY-MM-DD');
  • 삭제 쿼리가 실행된 후에, 삭제된 row가 저장공간에서 물리적으로 삭제되기 까지 걸리는 시간은, DBMS의 동작상황에 따라서 다를 수 있다The time it takes for the deleted row to be physically deleted from the storage space after the deletion query is executed may vary depending on the situation of the DBMS.

LOAD DATA INFILE

...

load_data_infile_stmt:

...

Code Block
sql
sql
load_data_infile_stmt: 'LOAD DATA INFILE' file_name 'INTO TABLE' table_name ( 'TABLESPACE' tbs_name )? ( 'AUTO' ( 'BULKLOAD' | 'HEADUSE' | 'HEADUSE_ESCAPE' ) )? ( ( 'FIELDS' | 'COLUMNS' ) ( 'TERMINATED BY' char )? ( 'ENCLOSED BY' char )? )? ( 'TRIM' ( 'ON' | 'OFF' ) )? ( 'IGNORE' number ( 'LINES' | 'ROWS' ) )? ( 'MAX_LINE_LENGTH' number )? ( 'ENCODED BY' coding_name )? ( 'ON ERROR' ( 'STOP' | 'IGNORE' ) )?


CSV 포맷의 데이터 파일을 서버에서 직접 읽어서, 옵션에 따라 서버에서 직접 테이블 및 컬럼들을 생성하여 이를 입력하는 기능이다.

각 옵션에 대해서 설명하면 다음과 같다.

...

옵션

...

format data files are read directly from the server, and tables and columns are created directly from the server according to the options and input them.
Each option is explained as follows

HEADUSE: 데이터 파일의 첫 번째 라인에 기술되어 있는 컬럼 명을 테이블의 컬럼명으로 사용하고, 그 라인에 기술된 수 만큼의 컬럼을 생성한다

Options

Description

AUTO mode_string

mode_string =

(BULKLOAD | HEADUSE | HEADUSE_ESCAPE)

해당 테이블을 생성하고 컬럼 타입(자동 생성시 varchar type) 및 컬럼명을 자동으로 생성한다.

BULKLOAD: 데이터 한 개의 row를 하나의 컬럼으로 입력한다. 컬럼으로 구분할 수 없는 데이터에 대해서 사용한다.

Creates the corresponding table and automatically generates the column type (varchar type for automatic creation) and the column name.
BULKLOAD: Enters one row of data as one column. It is used for data that can not be divided into columns.
HEADUSE: Uses the column name as described in the first line of the data file as the column name of the table, and creates as many columns as there are in the line.
HEADUSE_ESCAPE: Similar to the HEADUSE

옵션과 유사하지만, 컬럼명이 DB의 예약어와 같을 경우 발생할 수 있는 오류를 회피하기 위해 컬럼명의 앞뒤로 '_' 문자를 덧붙이고, 컬럼명에 특수문자가 존재하면 그 문자를 '_' 문자로 변경한다

option, but appends a '_' character to the front and back of the column name to avoid errors that can occur if the column name is the same as the reserved word in the DB. If a special character exists in the column name, changes it to '_'.

(FIELDS|COLUMNS) TERMINATED BY 'term_char'

ESCAPED BY 'escape_char'

데이터 라인을 파싱하기 위한 구분 문자

Specifies the delimiter (term_char)

와 이스케이프 문자

and escape character (escape_char)

를 지정한다. 일반적인 CSV 파일의 경우 구분 문자는 , 이며 이스케이프 문자는 '이다

for parsing the data line. For common CSV files, the delimiter is , and the escape character is '.

ENCODED BY coding_name

coding_name =

{ UTF8(default) | MS949 | KSC5601 | EUCJP | SHIFTJIS | BIG5 | GB231280 }

데이터 파일의 인코딩 옵션을 지정한다. 기본 값은 UTF-8이다

Specifies the encoding options for the data file. The default value is UTF-8.

TRIM (ON | OFF)

컬럼의 빈 공간을 제거하거나 유지한다. 기본값은 ON이다

Removes or maintains the empty space of the column. The default is ON.

IGNORE number (LINES | ROWS)

숫자로 지정된 라인 또는 행 만큼의 데이터를 무시한다. CSV 포맷 파일의 헤더 등을 무시하거나 VCF 헤더를 무시하기 위해서 사용한다

Ignores data for a specified number of lines or lines. It is used to ignore header of CSV format file or ignore VCF header.

MAX_LINE_LENGTH

한 라인의 최대 길이를 지정한다. 기본값은 512K이며, 데이터가 더 큰 경우에는 더 큰 값을 지정할 수 있다기본값은 IGNORE이다

Specifies the maximum length of one line. The default value is 512K. If the data is larger, you can specify a larger value.

ON ERROR (STOP | IGNORE)

입력 도중 에러가 발생할 경우 수행할 동작을 지정한다. STOP인 경우 입력을 중단하고 IGNORE인 경우 에러가 발생한 라인을 건너뛰고 계속 입력한다.

Specifies the action to take when an error occurs during input. If it is STOP, input is stopped. If it is IGNORE, the line where error occurred is skipped and input is continued.
The default is IGNORE.


Code Block
sql
sql
-- Use default field delimiter(,)  field encloser (") to 사용하여input 데이터를 입력한다data.
LOAD DATA INFILE '/tmp/aaa.csv' INTO TABLE Sample_data ; 

-- Create NEWTABLE 하나의with 컬럼을one 갖는column NEWTABLE을and 생성해서enter one 라인을line as 컬럼으로one 입력한다column. 
LOAD DATA INFILE '/tmp/bbb.csv' INTO TABLE NEWTABLE AUTO BULKLOAD; 

-- Create csv의NEWTABLE using 첫번째first 라인을line 컬럼of 정보로csv 이용하여as NEWTABLE을column 생성하고information, and 이를input it 테이블에into 입력한다table.

LOAD DATA INFILE '/tmp/bbb.csv' INTO TABLE NEWTABLE AUTO HEADUSE; 
 
-- 첫번째 라인은 무시하고 필드 구분자는 ; First line is ignored and field delimiter is ; and enclosing 문자는character 'is specified 지정해서by 입력한다'.

LOAD DATA INFILE '/tmp/ccc.csv' INTO TABLE Sample_data FIELDS TERMINATED BY ';' ENCLOSED BY '\''  IGNORE 1 LINES ON ERROR IGNORE;


Tip
AUTO 옵션을 사용하지 않는 경우 테이블의 모든 컬럼은 VARCHAR 또는 TEXT 타입으로 생성해야 한다
If the AUTO option is not used, all columns of the table must be created as VARCHAR or TEXT types.