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

Step 3: Creating a Foreign Table in GaussDB

Updated on 2024-10-14 GMT+08:00
  1. Use the SQL client tool to connect to the GaussDB database.
  2. Create a foreign table based on Table 1.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    openGauss=# DROP FOREIGN TABLE IF EXISTS product_info_ext;
    openGauss=# CREATE FOREIGN TABLE product_info_ext
    (
        product_price                integer        not null,
        product_id                   char(30)       not null,
        product_time                 date           ,
        product_level                char(10)       ,
        product_name                 varchar(200)   ,
        product_type1                varchar(20)    ,
        product_type2                char(10)       ,
        product_monthly_sales_cnt    integer        ,
        product_comment_time         date           ,
        product_comment_num          integer        ,
        product_comment_content      varchar(200)              
    ) 
    SERVER gsmpp_server 
    OPTIONS(
    LOCATION 'gsfs://192.168.0.90:5000/*',
    FORMAT 'CSV' ,
    DELIMITER ',',
    ENCODING 'utf8',
    HEADER 'false',
    FILL_MISSING_FIELDS 'true',
    IGNORE_EXTRA_DATA 'true'
    )
    READ ONLY
    LOG INTO product_info_err 
    PER NODE REJECT LIMIT 'unlimited';
    

    If the following information is displayed, the foreign table has been created:

    1
    CREATE FOREIGN TABLE
    
    Table 1 Configurations in the foreign table

    Configuration Item

    Value

    Description

    SERVER

    gsmpp_server

    Use the default value gsmpp_server.

    LOCATION

    gsfs://192.168.0.90:5000/*

    Location of source data files.

    If SSL is used for encrypted transmission, use the gsfss protocol. In this case, the location is gsfss://192.168.0.90:5000/*.

    FORMAT

    CSV

    Format of source data files.

    ENCODING

    UTF-8

    Data encoding format.

    DELIMITER

    It is set to a comma (,).

    Field separator.

    HEADER

    false (default value)

    Specifies whether a data file contains a header. This parameter is valid only for data files in CSV or FIXED format. The first line of data files in Preparing Source Data Files is not a header. Therefore, it is set to false.

    FILL_MISSING_FIELDS

    true

    Specifies how to handle the problem that the last column of a row in a source data file is lost during data import. The default value is false/off. true is used in this tutorial.

    • true/on: The last column is set to NULL. No error is reported.
    • false/off: Error "missing data for column "tt"" is reported.
    For example, the last column product_comment_content of the second row in the product_info2.csv source data file is lost. If FILL_MISSING_FIELDS is set to false/off, information similar to the following will be displayed in the error table during data import:
    missing data for column "product_comment_content"

    IGNORE_EXTRA_DATA

    true

    Specifies whether to ignore excessive columns when the number of columns in a source data file exceeds that defined in the foreign table. The default value is false/off. true is used in this tutorial.

    • true/on: The excessive columns of a row are ignored. No error is reported.
    • false/off: Error "extra data after last expected column" is reported.

    For example, the number of columns in the third record in the product_info2.csv source data file is greater than that defined in the foreign table. If IGNORE_EXTRA_DATA is set to false/off, information similar to the following will be displayed in the error table during data import:

    extra data after last expected column

    PER NODE REJECT LIMIT 'value'

    unlimited

    Maximum number of data format errors allowed on each DN during data import. If the number of errors exceeds the specified value on any DN, data import fails, an error is reported, and the system exits data import.

    It is set to unlimited in this tutorial, indicating that all data format errors during import are allowed.

    READ ONLY

    -

    Syntax defined in a foreign table can be used for both importing data to and exporting data from GaussDB. To import data to the cluster, use READ ONLY in the foreign table. To export data, use WRITE ONLY.

    WITH error_table_name

    Error table name: product_info_err

    Data format errors during import are recorded in the table specified by product_info_err. You can query this table after the import to obtain error details.

    For more configuration items, see CREATE FOREIGN TABLE (for Import and Export).

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