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

Help Center/ GaussDB(DWS)/ More Documents/ User Guide (Paris Region)/ FAQs/ Data Import and Export/ How Do I Implement Fault Tolerance Import Between Different Encoding Libraries

How Do I Implement Fault Tolerance Import Between Different Encoding Libraries

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

To import data from database A (UTF8) to database B (GBK), there may be a character set mismatch error which causes the data import to fail.

To import a small amount of data, run the \COPY command. The procedure is as follows:

  1. Create databases A and B. The encoding format of database A is UTF8, and that of database B is GBK.

    1
    2
    postgres=> CREATE DATABASE A ENCODING 'UTF8' template = template0;
    postgres=> CREATE DATABASE B ENCODING 'GBK' template = template0;
    

  2. View the database list. You can view the created databases A and B.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    postgres=> \l
                               List of databases
       Name    |  Owner  | Encoding  | Collate | Ctype | Access privileges
    -----------+---------+-----------+---------+-------+-------------------
     a         | dbadmin | UTF8      | C       | C     |
     b         | dbadmin | GBK       | C       | C     |
     gaussdb   | Ruby    | SQL_ASCII | C       | C     |
     postgres  | Ruby    | SQL_ASCII | C       | C     |
     template0 | Ruby    | SQL_ASCII | C       | C     | =c/Ruby          +
               |         |           |         |       | Ruby=CTc/Ruby
     template1 | Ruby    | SQL_ASCII | C       | C     | =c/Ruby          +
               |         |           |         |       | Ruby=CTc/Ruby
     xiaodi    | dbadmin | UTF8      | C       | C     |
    (7 rows)
    

  3. Switch to database A and enter the user password. Create a table named test01 and insert data into the table.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    postgres=> \c a
    Password for user dbadmin:
    SSL connection (protocol: TLSv1.3, cipher: TLS_AES_128_GCM_SHA256, bits: 128)
    You are now connected to database "a" as user "dbadmin".
    
    a=> CREATE TABLE test01
     (
         c_customer_sk             integer,
         c_customer_id             char(5),
         c_first_name              char(6),
         c_last_name               char(8)
     )
     with (orientation = column,compression=middle)
     distribute by hash (c_last_name);
    CREATE TABLE
    a=> INSERT INTO test01(c_customer_sk, c_customer_id, c_first_name) VALUES (3769, 'hello', 'Grace');
    INSERT 0 1
    a=> INSERT INTO test01 VALUES (456, 'good');
    INSERT 0 1
    

  4. Run the \COPY command to export data from the UTF8 library in Unicode format to the test01.dat file.

    1
    \copy test01 to '/opt/test01.dat' with (ENCODING 'Unicode');
    

  5. Switch to database B and create a table with the same name test01.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    a=> \c b
    Password for user dbadmin:
    SSL connection (protocol: TLSv1.3, cipher: TLS_AES_128_GCM_SHA256, bits: 128)
    You are now connected to database "b" as user "dbadmin".
    
    b=> CREATE TABLE test01
     (
         c_customer_sk             integer,
         c_customer_id             char(5),
         c_first_name              char(6),
         c_last_name               char(8)
     )
     with (orientation = column,compression=middle)
     distribute by hash (c_last_name);
    

  6. Run the \COPY command to import the test01.dat file to database B.

    1
    \copy test01 from '/opt/test01.dat' with (ENCODING 'Unicode' ,COMPATIBLE_ILLEGAL_CHARS 'true');
    
    NOTE:
    • The error tolerance parameter COMPATIBLE_ILLEGAL_CHARS specifies that invalid characters are tolerated during data import. Invalid characters are converted and then imported to the database. No error message is displayed. The import is not interrupted.
    • The BINARY format is not supported. When data of such format is imported, error "cannot specify bulkload compatibility options in BINARY mode" will occur.
    • The parameter is valid only for data importing using the COPY FROM option.

  7. View data in the test01 table in database B.

    1
    2
    3
    4
    5
    6
    b=> select * from test01;
     c_customer_sk | c_customer_id | c_first_name | c_last_name
    ---------------+---------------+--------------+-------------
              3769 | hello         | Grace        |
               456 | good          |              |
    (2 rows)
    

  8. After the preceding operations are performed, data is imported from database A (UTF8) to database B (GBK).

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