Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

SQL

Updated on 2024-12-06 GMT+08:00

GaussDB is compatible with most MySQL syntax, but there are some differences. This section describes the MySQL syntax supported by GaussDB.

  • Some keywords can be used as identifiers in MySQL, but cannot or are restricted to be identifiers in M-compatible mode, as listed in Table 1.
    Table 1 Keywords restricted to be identifiers

    Keyword Type

    Keyword

    Constraint

    Reserved (Type or function is allowed.)

    COLLATION and COMPACT

    They cannot be used as identifiers in other databases except for functions and variables.

    Non-reserved (Type or function is not allowed.)

    BIT, BOOLEAN, COALESCE, DATE, NATIONAL, NCHAR, NONE, NUMBER, TEXT, TIME, TIMESTAMP, and TIMESTAMPDIFF

    They cannot be used as identifiers for functions or variables.

    Reserved

    ANY, ARRAY, BUCKETS, DO, END, LESS, MODIFY, OFFSET, ONLY, RETURNING, SOME, and USER

    They cannot be used as identifiers in any database.

  • The GaussDB optimizer is different from the MySQL optimizer. Due to the difference in the execution plans generated by optimizers, the GaussDB behavior may be inconsistent with the MySQL behavior, but it does not affect the service data result.

    For example, in the following scenario, when GaussDB calculates col1 and uses col1 for WHERE comparison, the cast function is called and two WARNING records are generated.

    MySQL calls the cast function when calculating col1. During WHERE comparison, the calculated value is used for comparison. As a result, a WARNING record is generated.

    -- Behavior in GaussDB:
    m_db=# select * from (select cast('abc' as decimal) as col1) t1 where col1=0;
    WARNING:  Truncated incorrect DECIMAL value: 'abc'
    WARNING:  Truncated incorrect DECIMAL value: 'abc'
    CONTEXT:  referenced column: col1
     col1 
    ------
        0
    (1 row)
    
    m_db=# explain verbose select * from (select cast('abc' as decimal) as col1) t1 where col1=0;
    WARNING:  Truncated incorrect DECIMAL value: 'abc'
    WARNING:  Truncated incorrect DECIMAL value: 'abc'
    CONTEXT:  referenced column: col1
                    QUERY PLAN                
    ------------------------------------------
     Result  (cost=0.00..0.01 rows=1 width=0)
       Output: 0::decimal
    (2 rows)
    
    -- Behavior in MySQL:
    mysql>  select * from (select cast('abc' as decimal) as col1) t1 where col1=0;
    +------+
    | col1 |
    +------+
    |    0 |
    +------+
    1 row in set, 1 warning (0.00 sec)
    
    mysql> show warnings;
    +---------+------+------------------------------------------+
    | Level   | Code | Message                                  |
    +---------+------+------------------------------------------+
    | Warning | 1292 | Truncated incorrect DECIMAL value: 'abc' |
    +---------+------+------------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> explain select * from (select cast('abc' as decimal) as col1) t1 where col1=0;
    +----+-------------+------------+------------+--------+---------------+------+---------+------+------+----------+----------------+
    | id | select_type | table      | partitions | type   | possible_keys | key  | key_len | ref  | rows | filtered | Extra          |
    +----+-------------+------------+------------+--------+---------------+------+---------+------+------+----------+----------------+
    |  1 | PRIMARY     | <derived2> | NULL       | system | NULL          | NULL | NULL    | NULL |    1 |   100.00 | NULL           |
    |  2 | DERIVED     | NULL       | NULL       | NULL   | NULL          | NULL | NULL    | NULL | NULL |     NULL | No tables used |
    +----+-------------+------------+------------+--------+---------------+------+---------+------+------+----------+----------------+
    2 rows in set, 2 warnings (0.01 sec)
    
    mysql> show warnings;
    +---------+------+---------------------------------------------------------------+
    | Level   | Code | Message                                                       |
    +---------+------+---------------------------------------------------------------+
    | Warning | 1292 | Truncated incorrect DECIMAL value: 'abc'                      |
    | Note    | 1003 | /* select#1 */ select '0' AS `col1` from dual where ('0' = 0) |
    +---------+------+---------------------------------------------------------------+
    2 rows in set (0.00 sec)
    

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback