INSERT
statement but not UPDATE
, DELETE
, and SELECT
statements.CREATE EXTENSION IF NOT EXISTS cos_ext SCHEMA public;
DROP EXTENSION IF EXISTS cos_ext;
CREATE [READABLE] EXTERNAL TABLE tablename( columnname datatype [, ...] | LIKE othertable )LOCATION (cos_ext_params)FORMAT 'TEXT'[( [HEADER][DELIMITER [AS] 'delimiter' | 'OFF'][NULL [AS] 'null string'][ESCAPE [AS] 'escape' | 'OFF'][NEWLINE [ AS ] 'LF' | 'CR' | 'CRLF'][FILL MISSING FIELDS] )]| 'CSV'[( [HEADER][QUOTE [AS] 'quote'][DELIMITER [AS] 'delimiter'][NULL [AS] 'null string'][FORCE NOT NULL column [, ...]][ESCAPE [AS] 'escape'][NEWLINE [ AS ] 'LF' | 'CR' | 'CRLF'][FILL MISSING FIELDS] )][ ENCODING 'encoding' ][ [LOG ERRORS [INTO error_table]] SEGMENT REJECT LIMIT count[ROWS | PERCENT] ]
CREATE WRITABLE EXTERNAL TABLE table_name( column_name data_type [, ...] | LIKE other_table )LOCATION (cos_ext_params)FORMAT 'TEXT'[( [DELIMITER [AS] 'delimiter'][NULL [AS] 'null string'][ESCAPE [AS] 'escape' | 'OFF'] )]| 'CSV'[([QUOTE [AS] 'quote'][DELIMITER [AS] 'delimiter'][NULL [AS] 'null string'][FORCE QUOTE column [, ...] ][ESCAPE [AS] 'escape'] )][ ENCODING 'encoding' ][ DISTRIBUTED BY (column, [ ... ] ) | DISTRIBUTED RANDOMLY ]
cos_ext_params
descriptioncos://cos_endpoint/bucket/prefix secretId=id secretKey=key compressType=[none|gzip] https=[true|false]
Parameter | Format | Required | Description |
URL | COS V4: cos://cos.{REGION}.myqcloud.com/{BUCKET}/{PREFIX} COS V5: cos:// {BUCKET}-{APPID}.cos.{REGION}.myqcloud.com/{PREFIX} | Yes | |
secretId | None | Yes | Secret ID used for API access. See API Key Management |
secretKey | None | Yes | Secret key used for API access. See API Key Management |
HTTPS | true Ι false | No | Whether to use HTTPS to access COS. Default value: true |
compressType | gzip | No | Whether to compress COS files. Default value: empty (not to compress) |
APPID
. If you see the bucket name test-123123123
in the list, just enter "test".prefix
specifies the name prefix of the object to be read.
If prefix
is empty, all files in the bucket will be read; if it ends with "/", all files in the folder and subfolders will be matched; otherwise, all files in the folder and subfolders matched by prefix
will be read. For example, COS objects include read-bucket/simple/a.csv
, read-bucket/simple/b.csv
, read-bucket/simple/dir/c.csv
, and read-bucket/simple_prefix/d.csv
.prefix
is specified as simple
, all files will be read, including simple_prefix
with the matching directory name prefix. The following is the list of objects:
read-bucket/simple/a.csv
read-bucket/simple/b.csv
read-bucket/simple/dir/c.csv
read-bucket/simple_prefix/d.csvprefix
is specified as simple/
, all files including simple/
will be read, including:
read-bucket/simple/a.csv
read-bucket/simple/b.csv
read-bucket/simple/dir/c.csvprefix
specifies the output file prefix.
If no prefix
is specified, files will be written to the bucket. If prefix
ends with "/", files will be written to the directory specified by prefix
; otherwise, files will be prefixed with the given prefix
. For example, if the files that need to be created include a.csv
, b.csv
, and c.csv
, then:prefix
is specified as simple/
, the following objects will be generated:
read-bucket/simple/a.csv
read-bucket/simple/b.csv
read-bucket/simple/b.csvprefix
is specified as simple\\_
, the following objects will be generated:
read-bucket/simple_a.csv
read-bucket/simple_b.csv
read-bucket/simple_b.csvCREATE EXTENSION IF NOT EXISTS cos_ext SCHEMA public;
CREATE TABLE cos_local_tbl (c1 int, c2 text, c3 int)DISTRIBUTED BY (c1);
simple-bucket
in Guangzhou.CREATE READABLE EXTERNAL TABLE cos_tbl (c1 int, c2 text, c3 int)LOCATION('cos://cos.ap-guangzhou.myqcloud.com/simple-bucket/from_cos/ secretKey=xxx secretId=xxx')FORMAT 'csv';
from_cos
directory in simple-bucket
with the following content:1,simple line 1,12,simple line 1,13,simple line 1,14,simple line 1,15,simple line 1,16,simple line 2,17,simple line 2,18,simple line 2,19,simple line 2,1
INSERT INTO cos_local_tbl SELECT * FROM cos_tbl;
SELECT count(1) FROM cos_local_tbl;SELECT count(1) FROM cos_tbl;
CREATE EXTENSION IF NOT EXISTS cos_ext SCHEMA public;
CREATE TABLE cos_local_tbl (c1 int, c2 text, c3 int)DISTRIBUTED BY (c1);
simple-bucket
in Guangzhou.CREATE WRITABLE EXTERNAL TABLE cos_tbl_wr (c1 int, c2 text, c3 int)LOCATION('cos://cos.ap-guangzhou.myqcloud.com/simple-bucket/to-cos/ secretKey=xxx secretId=xxx')FORMAT 'csv';
insert into cos_local_tbl values(1, 'simple line 1' , 1),(2, 'simple line 2', 2),(3, 'simple line 3', 3) ,(4, 'simple line 4', 4) ,(5, 'simple line 5', 5) ,(6, 'simple line 6', 6) ,(7, 'simple line 7', 7) ,(8, 'simple line 8', 8) ,(9, 'simple line 9', 9);
INSERT INTO cos_tbl_wr SELECT * FROM cos_local_tbl;
CREATE EXTENSION IF NOT EXISTS cos_ext SCHEMA public;
for-dml
directory in simple-bucket
with the following content:1,simple line 1,12,simple line 1,13,simple line 1,14,simple line 1,15,simple line 1,16,simple line 2,17,simple line 2,18,simple line 2,19,simple line 2,1
CREATE READABLE EXTERNAL TABLE cos_tbl_dml (c1 int, c2 text, c3 int)LOCATION('cos://cos.ap-guangzhou.myqcloud.com/simple-bucket/for-dml/ secretKey=xxx secretId=xxx')FORMAT 'csv';
SELECT c2, sum(c1) FROM cos_tbl GROUP BY c2;
Was this page helpful?