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

Range Functions and Operators

Updated on 2022-07-29 GMT+08:00

Range Operators

  • =

    Description: Equals

    For example:

    1
    2
    3
    4
    5
    SELECT int4range(1,5) = '[1,4]'::int4range AS RESULT;
     result
    --------
     t
    (1 row)
    
  • <>

    Description: Does not equal to

    For example:

    1
    2
    3
    4
    5
    SELECT numrange(1.1,2.2) <> numrange(1.1,2.3) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • <

    Description: Is less than

    For example:

    1
    2
    3
    4
    5
    SELECT int4range(1,10) < int4range(2,3) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • >

    Description: Is greater than

    For example:

    1
    2
    3
    4
    5
    SELECT int4range(1,10) > int4range(1,5) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • <=

    Description: Is less than or equals

    For example:

    1
    2
    3
    4
    5
    SELECT numrange(1.1,2.2) <= numrange(1.1,2.2) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • >=

    Description: Is greater than or equals

    For example:

    1
    2
    3
    4
    5
    SELECT numrange(1.1,2.2) >= numrange(1.1,2.0) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • @>

    Description: Contains range

    For example:

    1
    2
    3
    4
    5
    SELECT int4range(2,4) @> int4range(2,3) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • @>

    Description: Contains element

    For example:

    1
    2
    3
    4
    5
    SELECT '[2011-01-01,2011-03-01)'::tsrange @> '2011-01-10'::timestamp AS RESULT;
     result
    --------
     t
    (1 row)
    
  • <@

    Description: Range is contained by

    For example:

    1
    2
    3
    4
    5
    SELECT int4range(2,4) <@ int4range(1,7) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • <@

    Description: Element is contained by

    For example:

    1
    2
    3
    4
    5
    SELECT 42 <@ int4range(1,7) AS RESULT;
     result
    --------
     f
    (1 row)
    
  • &&

    Description: Overlap (have points in common)

    For example:

    1
    2
    3
    4
    5
    SELECT int8range(3,7) && int8range(4,12) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • <<

    Description: Strictly left of

    For example:

    1
    2
    3
    4
    5
    SELECT int8range(1,10) << int8range(100,110) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • >>

    Description: Strictly right of

    For example:

    1
    2
    3
    4
    5
    SELECT int8range(50,60) >> int8range(20,30) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • &<

    Description: Does not extend to the right of

    For example:

    1
    2
    3
    4
    5
    SELECT int8range(1,20) &< int8range(18,20) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • &>

    Description: Does not extend to the left of

    For example:

    1
    2
    3
    4
    5
    SELECT int8range(7,20) &> int8range(5,10) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • -|-

    Description: Is adjacent to

    For example:

    1
    2
    3
    4
    5
    SELECT numrange(1.1,2.2) -|- numrange(2.2,3.3) AS RESULT;
     result
    --------
     t
    (1 row)
    
  • +

    Description: Union

    For example:

    1
    2
    3
    4
    5
    SELECT numrange(5,15) + numrange(10,20) AS RESULT;
     result 
    --------
     [5,20)
    (1 row)
    
  • *

    Description: Intersection

    For example:

    1
    2
    3
    4
    5
    SELECT int8range(5,15) * int8range(10,20) AS RESULT;
     result  
    ---------
     [10,15)
    (1 row)
    
  • -

    Description: Difference

    For example:

    1
    2
    3
    4
    5
    SELECT int8range(5,15) - int8range(10,20) AS RESULT;
     result 
    --------
     [5,10)
    (1 row)
    

The simple comparison operators <, >, <=, and >= compare the lower bounds first, and only if those are equal, compare the upper bounds.

The <<, >>, and -|- operators always return false when an empty range is involved; that is, an empty range is not considered to be either before or after any other range.

The union and difference operators will fail if the resulting range would need to contain two disjoint sub-ranges.

Range Functions

  • lower(anyrange)

    Description: Lower bound of range

    Return type: Range's element type

    For example:

    1
    2
    3
    4
    5
    SELECT lower(numrange(1.1,2.2)) AS RESULT;
     result 
    --------
        1.1
    (1 row)
    
  • upper(anyrange)

    Description: Upper bound of range

    Return type: Range's element type

    For example:

    1
    2
    3
    4
    5
    SELECT upper(numrange(1.1,2.2)) AS RESULT;
     result 
    --------
        2.2
    (1 row)
    
  • isempty(anyrange)

    Description: Is the range empty?

    Return type: boolean

    For example:

    1
    2
    3
    4
    5
    SELECT isempty(numrange(1.1,2.2)) AS RESULT;
     result 
    --------
     f
    (1 row)
    
  • lower_inc(anyrange)

    Description: Is the lower bound inclusive?

    Return type: boolean

    For example:

    1
    2
    3
    4
    5
    SELECT lower_inc(numrange(1.1,2.2)) AS RESULT;
     result 
    --------
     t
    (1 row)
    
  • upper_inc(anyrange)

    Description: Is the upper bound inclusive?

    Return type: boolean

    For example:

    1
    2
    3
    4
    5
    SELECT upper_inc(numrange(1.1,2.2)) AS RESULT;
     result 
    --------
     f
    (1 row)
    
  • lower_inf(anyrange)

    Description: Is the lower bound infinite?

    Return type: boolean

    For example:

    1
    2
    3
    4
    5
    SELECT lower_inf('(,)'::daterange) AS RESULT;
     result 
    --------
     t
    (1 row)
    
  • upper_inf(anyrange)

    Description: Is the upper bound infinite?

    Return type: boolean

    For example:

    1
    2
    3
    4
    5
    SELECT upper_inf('(,)'::daterange) AS RESULT;
     result 
    --------
     t
    (1 row)
    

The lower and upper functions return null if the range is empty or the requested bound is infinite. The lower_inc, upper_inc, lower_inf, and upper_inf functions all return false for an empty range.

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