General syntax

2024-04-19 08:42:50  Updated

This topic describes the general syntax of SQL statements, including the syntax of constants, character sets, data types, SQL properties, distributed properties, and storage properties.

Constants

  • INT_VALUE: matches integer constants such as 123.

  • DECIMAL_VALUE: matches fixed-point constants such as 123.456.

  • STR_VALUE: matches string constants such as abc.

  • NULL: matches NULL constants.

  • STORAGE_SIZE: matches storage size constants. The default unit of integer values is bytes, and the unit of string values can be set to M or G. For example, the size can be 1024 or '500M'.

const_value:
      INT_VALUE
    | DECIMAL_VALUE
    | STR_VALUE
    | NULL
    | STORAGE_SIZE

STORAGE_SIZE:
      INT_VALUE
    | 'INT_VALUE[M|G]'

Character sets

charset:
      default_charset
    | column_charset

default_charset:
    [DEFAULT] {CHARSET | CHARACTER SET} [=] {UTF8 | UTF8MB4 | BINARY}

column_charset:
    {CHARSET | CHARACTER SET} {UTF8 | UTF8MB4 | BINARY}

Collations

collate:
      default_collate
    | column_collate

default_collate:
    [DEFAULT] COLLATE [=] {UTF8MB4_GENERAL_CI | UTF8MB4_BIN | BINARY}

column_collate:
    COLLATE {UTF8MB4_GENERAL_CI | UTF8MB4_BIN | BINARY}

Data types

data_type:
      TINYINT[(precision)] [UNSIGNED] [ZEROFILL]
    | SMALLINT[(precision)] [UNSIGNED] [ZEROFILL]
    | MEDIUMINT[(precision)] [UNSIGNED] [ZEROFILL]
    | INT[(precision)] [UNSIGNED] [ZEROFILL]
    | INTEGER[(precision)] [UNSIGNED] [ZEROFILL]
    | BIGINT[(precision)] [UNSIGNED] [ZEROFILL]
    | FLOAT[(precision, scale)] [UNSIGNED] [ZEROFILL]
    | DOUBLE[(precision, scale)] [UNSIGNED] [ZEROFILL]
    | DECIMAL[(precision [, scale])] [UNSIGNED] [ZEROFILL]
    | NUMERIC[(precision [, scale])] [UNSIGNED] [ZEROFILL]
    | DATETIME[(scale)]
    | TIMESTAMP[(scale)]
    | DATE
    | TIME[(scale)]
    | YEAR
    | VARCHAR(length) column_charset column_collate
    | VARBINARY(length)
    | CHAR[(length)] column_charset column_collate
    | BINARY[(length)]
    | TINYTEXT column_charset column_collate
    | TINYLOB
    | TEXT[(length)] column_charset column_collate
    | BLOB[(length)]
    | MEDIUMTEXT column_charset column_collate
    | MEDIUMBLOB
    | LONGTEXT column_charset column_collate
    | LONGBLOB

precision | scale | length:
    INT_VALUE

SQL properties

  • Object name

    tenant_name | pool_name | unit_name | zone_name | region_name:
        STR_VALUE
    
    database_name | table_name | table_alias_name | column_name| column_alias_name  | partition_name | subpartition_name:
        STR_VALUE
    
    index_name | view_name | object_name | constraint_name | tablegroup_name:
        STR_VALUE
    
    outline_name | user_name:
        STR_VALUE
    
    table_factor:
        [[database_name].] table_name
    
    column_factor:
        [table_factor.] column_name
    
  • Expression

    expression:
          const_value
        | column_factor
        | operator_expression
        | function_expression
    
  • Comment

    comment:
        COMMENT 'comment_text'
    
    comment_text:
        STR_VALUE
    

Distributed properties

  • PRIMARY_ZONE: specifies the leader distribution strategy for data.

    primary_zone:
    PRIMARY_ZONE [=] zone_name
    
  • ZONE_LIST: specifies the resource distribution strategy for a tenant.

    zone_list:
    ZONE_LIST [=] (zone_name [, zone_name ...])
    
  • REPLICA_NUM: specifies the number of replicas of data.

    replica_num:
    REPLICA_NUM [=] INT_VALUE
    
  • TABLEGROUP: specifies the leader distribution strategy for multiple data replicas.

    tablegroup:
          default_tablegroup
        | table_tablegroup
    
    default_tablegroup:
        DEFAULT TABLEGROUP [=] {tablegroup_name | NULL}
    
    table_tablegroup:
        TABLEGROUP [=] {tablegroup_name | NULL}
    

Storage properties

  • BLOCK_SIZE: specifies the microblock size for object storage.

    block_size:
    BLOCK_SIZE [=] INT_VALUE
    
  • COMPRESSION: specifies the compression algorithm for object storage.

    compression:
    COMPRESSION [=] {NONE | LZ4_1.0 | LZ0_1.0 | SNAPPY_1.0 | ZLIB_1.0}
    

    Note

    The zlib compression algorithm of different minor versions may generate different compression results for the same data. To avoid replica restore failures during an upgrade, the zlib_1.0 compression algorithm is no longer supported starting from OceanBase Database V4.3.0.

  • PCTFREE: specifies the macroblock reservation percentage for object storage.

    pctfree:
    PCTFREE [=] INT_VALUE
    
  • TABLET_SIZE: specifies the minimum tablet size of a single task in a parallel compaction.

    tablet_size:
    TABLET_SIZE [=] INT_VALUE
    

Contact Us