Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

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

DISCARD

Updated on 2025-01-13 GMT+08:00

Function

Releases internal resources related to database sessions. The DISCARD command is used to reset the status of some or all sessions. Different DISCARD clauses release different types of resources. The DISCARD ALL command releases all temporary resources related to the current session and resets them to the initial state.

Precautions

None

Syntax

1
2
3
DISCARD 
        { VOLATILE { TEMPORARY | TEMP } }  |
        { ALL | TEMP | TEMPORARY | PLANS | SEQUENCES } }

Parameter Description

  • VOLATILE { TEMPORARY | TEMP }

    Releases resources related to the VOLATILE temporary table in the current session.

    CAUTION:

    After the DISCARD VOLATILE { TEMPORARY | TEMP } statement is executed, all volatile temporary table resources in the current session will be cleared. However, the statement cannot clear a single volatile temporary table resource.

  • GLOBAL { TEMPORARY | TEMP } [ TABLE table_name ]
    • Run the DISCARD GLOBAL TEMP command to release resources related to the global temporary table in the current session.
    • DISCARD GLOBAL TEMP TABLE table_name releases resources of a specified global temporary table in the current session.
    CAUTION:

    If a global temporary table occupies resources in a session, you need to run the DISCARD command to clear the resources of all sessions before performing DDL operations.

  • TEMP | TEMPORARY

    Releases resources related to all temporary tables in the current session, including volatile and global temporary tables.

  • PLANS

    Releases all cached query plans in the current session and forces them to be replanned when related PREPARE statements are used next time.

  • SEQUENCES

    Discards all cached sequence-related states, including currval()/lastval() information and any pre-allocated sequence values that have not been returned through nextval().

  • ALL

    Releases all temporary resources related to the current session and resets them to their initial state. This has almost the same effect as executing the following statement sequence:

    SET SESSION AUTHORIZATION DEFAULT; 
    RESET ALL; 
    DEALLOCATE ALL; 
    CLOSE ALL; 
    UNLISTEN *; 
    SELECT pg_advisory_unlock_all(); 
    DISCARD PLANS; DISCARD SEQUENCES; 
    DISCARD TEMP;
    CAUTION:
    • After DISCARD ALL is executed successfully, schemas starting with pg_temp and pg_toast_temp are also deleted.
    • DISCARD ALL cannot be executed in a transaction.

Examples

  • DISCARD global temporary tables
    CREATE GLOBAL TEMP TABLE t_global_temp(a int,b int);
    NOTICE:  The 'DISTRIBUTE BY' clause is not specified. Using round-robin as the distribution mode by default.
    HINT:  Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column.
    CREATE TABLE
    
    INSERT INTO t_global_temp VALUES(1,1),(2,2);
    INSERT 0 2
    
    DROP TABLE t_global_temp;
    ERROR:  can not DROP TABLE when global temp table "t_global_temp" is in use
    
    DISCARD GLOBAL TEMP TABLE t_global_temp;
    
    DROP TABLE t_global_temp;
    DROP TABLE
  • DISCARD VOLATILE temporary tables

    After the DISCARD operation is performed, all resources related to volatile temporary tables in the current session are cleared.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    CREATE VOLATILE TEMP TABLE TX1(A INT) DISTRIBUTE BY HASH(A);
    CREATE TABLE
    CREATE VOLATILE TEMP TABLE TX2(A INT) DISTRIBUTE BY HASH(A);
    CREATE TABLE
    
    SELECT * FROM TX1;
     a
    ---
    (0 rows)
    SELECT * FROM TX2;
     a
    ---
    (0 rows)
    
    DISCARD VOLATILE TEMP;
    
    SELECT * FROM TX1;
    ERROR:  relation "tx1" does not exist
    LINE 1: SELECT * FROM TX1;
                          ^
    SELECT * FROM TX2;
    ERROR:  relation "tx2" does not exist
    LINE 1: SELECT * FROM TX2;
    
  • DISCARD TEMP
    After DISCARD TEMP is run, all temporary table resources in the current session are cleared.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    CREATE GLOBAL TEMP TABLE t_global_temp(a int,b int);
    NOTICE:  The 'DISTRIBUTE BY' clause is not specified. Using round-robin as the distribution mode by default.
    HINT:  Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column.
    CREATE TABLE
    INSERT INTO t_global_temp VALUES(1,1),(2,2);
    INSERT 0 2
    
    CREATE VOLATILE TEMP TABLE t_volatile_temp(a int,b int);
    CREATE TEMP TABLE t_temp(a int,b int);
    
    DISCARD TEMP;
    
    SELECT * FROM t_global_temp;
     a | b
    ---+---
    (0 rows)
    
    SELECT * FROM t_volatile_temp;
    ERROR:  relation "t_volatile_temp" does not exist
    LINE 1: select * from t_volatile_temp;
    
    SELECT * FROM t_temp;
    ERROR:  relation "t_temp" does not exist
    LINE 1: select * from t_temp;
    

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback