云数据库 GAUSSDB-COPY:语法格式

时间:2024-11-13 14:46:59

语法格式

  • 从一个文件复制数据到一个表。
    COPY table_name [ ( column_name [, ...] ) ] 
        FROM { 'filename' | STDIN }
        [ [ USING ] DELIMITERS 'delimiters' ]
        [ WITHOUT ESCAPING ]
        [  LOG  ERRORS ]
        [ LOG ERRORS DATA ]
        [ REJECT LIMIT 'limit' ]
        [ [ WITH ] 
            ( option [, ...] )
            | ( copy_option [, ...] )
            | [ TRANSFORM ( { column_name [ data_type ] [ AS transform_expr ] } [, ...] ) ]
            | [ FIXED FORMATTER ( { column_name( offset, length ) } [, ...] ) ]
        ];

    上述语法中fixed formatter与copy_option语法兼容、与option语法不兼容;copy_option与option语法不兼容;transform与copy_option、fixed formatter语法兼容。

  • 把一个表的数据复制到一个文件。
    COPY table_name [ ( column_name [, ...] ) ]
        TO { 'filename' | STDOUT }
        [ [ USING ] DELIMITERS 'delimiters' ]
        [ WITHOUT ESCAPING ]
        [ [ WITH ] 
            ( option [, ...] )
            | ( copy_option[, ...] )
            | [ FIXED FORMATTER ( { column_name( offset, length ) } [, ...] ) ]
        ];
    
    COPY query {(SELECT) | (VALUES)}
        TO { 'filename' | STDOUT }
        [ WITHOUT ESCAPING ]
        [ [ WITH ] 
            ( option [, ...] )
            | ( copy_option [, ...] )
            | [ FIXED FORMATTER ( { column_name( offset, length ) } [, ...] ) ]
        ];
    • COPY TO语法形式约束如下:

      (query)与[USING] DELIMITERS不兼容,即若COPY TO的数据来自于一个query的查询结果,那么COPY TO语法不能再指定[USING] DELIMITERS语法子句。

    • 对于FIXED FORMATTTER语法后面跟随的copy_option是以空格进行分隔的。
    • copy_option是指COPY原生的参数形式,而option是兼容外表导入的参数形式。
    其中可选参数option子句语法为:
    FORMAT 'format_name'
    | FORMAT binary
    | OIDS [ boolean ]
    | DELIMITER 'delimiter_character'
    | NULL 'null_string'
    | HEADER [ boolean ]
    | USEEOF [ boolean ]
    | FILEHEADER 'header_file_string'
    | FREEZE [ boolean ]
    | QUOTE 'quote_character'
    | ESCAPE 'escape_character'
    | EOL 'newline_character'
    | NOESCAPING [ boolean ]
    | FORCE_QUOTE { ( column_name [, ...] ) | * }
    | FORCE_NOT_NULL ( column_name [, ...] )
    | ENCODING 'encoding_name'
    | IGNORE_EXTRA_DATA [ boolean ]
    | FILL_MISSING_FIELDS [ boolean ]
    | COMPATIBLE_ILLEGAL_CHARS [ boolean ]
    | DATE_FORMAT 'date_format_string'
    | TIME_FORMAT 'time_format_string'
    | TIMESTAMP_FORMAT 'timestamp_format_string'
    | SMALLDATETIME_FORMAT 'smalldatetime_format_string'
    其中可选参数copy_option子句语法为:
    OIDS
    | NULL 'null_string' 
    | HEADER 
    | USEEOF
    | FILEHEADER 'header_file_string' 
    | FREEZE 
    | FORCE_NOT_NULL column_name [, ...]
    | FORCE_QUOTE { column_name [, ...] | * }
    | BINARY 
    |  CS V 
    | QUOTE [ AS ] 'quote_character' 
    | ESCAPE [ AS ] 'escape_character' 
    | EOL 'newline_character'
    | ENCODING 'encoding_name' 
    | IGNORE_EXTRA_DATA 
    | FILL_MISSING_FIELDS [ { 'one' | 'multi' } ]
    | COMPATIBLE_ILLEGAL_CHARS 
    | DATE_FORMAT 'date_format_string' 
    | TIME_FORMAT 'time_format_string' 
    | TIMESTAMP_FORMAT 'timestamp_format_string' 
    | SMALLDATETIME_FORMAT 'smalldatetime_format_string'
    | SKIP int_number
    | WHEN { ( start - end ) | column_name } { = | != } 'string'
    | SEQUENCE ( { column_name ( integer [, incr] ) [, ...] } )
    | FILLER ( { column_name [, ...] } )
    | CONSTANT ( { column_name 'constant_string' [, ...] } )
support.huaweicloud.com/centralized-devg-v8-gaussdb/gaussdb-42-0534.html