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

UPDATE

Updated on 2022-08-16 GMT+08:00

Function

UPDATE updates data in a table. UPDATE changes the values of the specified columns in all rows that satisfy the condition. The WHERE clause clarifies conditions. The columns to be modified need be mentioned in the SET clause; columns not explicitly modified retain their previous values.

Precautions

  • You must have the UPDATE permission on a table to be updated.
  • You must have the SELECT permission on all tables involved in the expressions or conditions.
  • The distribution column of a table cannot be modified.
  • For column-store tables, the RETURNING clause is currently not supported.
  • Column-store tables do not support non-deterministic update. If you update data in one row with multiple rows of data in a column-store table, an error is reported.
  • Memory space that records update operations in column-store tables is not reclaimed. You need to clean it by executing VACUUM FULL table_name.
  • Currently, UPDATE cannot be used in column-store replication tables.
  • You are not advised to create a table that needs to be frequently updated as a replication table.
  • Column-store tables support lightweight UPDATE operations. Lightweight UPDATE operations only rewrite the updated columns to reduce space usage. Lightweight UPDATE for column-store tables is controlled by GUC parameter enable_light_colupdate.
  • Column-store lightweight UPDATE is unavailable and automatically changes to the regular UPDATE operation in the following scenarios: updating an index column, updating a primary key column, updating a partition column, updating a PCK column, and online scaling.

Syntax

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ]
SET {column_name = { expression | DEFAULT } 
    |( column_name [, ...] ) = {( { expression | DEFAULT } [, ...] ) |sub_query }}[, ...]
    [ FROM from_list] [ WHERE condition ]
    [ RETURNING {* 
                | {output_expression [ [ AS ] output_name ]} [, ...] }];

where sub_query can be:
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
{ * | {expression [ [ AS ] output_name ]} [, ...] }
[ FROM from_item [, ...] ]
[ WHERE condition ]
[ GROUP BY grouping_element [, ...] ]
[ HAVING condition [, ...] ]

Parameter Description

  • table_name

    Name (optionally schema-qualified) of the table to be updated.

    Value range: an existing table name

  • alias

    Specifies the alias for the target table.

    Value range: a string. It must comply with the naming convention.

  • column_name

    Renames a column.

    You can refer to this column by specifying the table name and column name of the target table. Example:

    UPDATE foo SET foo.col_name = 'GaussDB';

    You can refer to this column by specifying the target table alias and the column name. For example:

    UPDATE foo AS f SET f.col_name = 'GaussDB';

    Value range: an existing column name

  • expression

    An expression or value to assign to the column.

  • DEFAULT

    Sets the column to its default value.

    The value is NULL if no specified default value has been assigned to it.

  • sub_query

    Specifies a subquery.

    This command can be executed to update a table with information for other tables in the same database. For details about clauses in the SELECT statement, see SELECT.

  • from_list

    A list of table expressions, allowing columns from other tables to appear in the WHERE condition and the update expressions. This is similar to the list of tables that can be specified in the FROM clause of a SELECT statement.

    NOTICE:

    Note that the target table must not appear in the from_list, unless you intend a self-join (in which case it must appear with an alias in the from_list).

  • condition

    An expression that returns a value of type boolean. Only rows for which this expression returns true are updated.

  • output_expression

    An expression to be computed and returned by the UPDATE command after each row is updated.

    Value range: The expression can use any column names of the table named by table_name or table(s) listed in FROM. Write * to return all columns.

  • output_name

    A name to use for a returned column.

Examples

Create the student1 table.

1
2
3
4
5
6
CREATE TABLE student1
(
   stuno     int,
   classno   int 
) 
DISTRIBUTE BY hash(stuno);

Insert data.

1
2
3
INSERT INTO student1 VALUES(1,1);
INSERT INTO student1 VALUES(2,2);
INSERT INTO student1 VALUES(3,3);

View data.

1
SELECT * FROM student1;

Update the values of all records.

1
UPDATE student1 SET classno = classno*2;

View data.

1
SELECT * FROM student1;

Delete a table.

1
DROP TABLE student1;

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