File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
77warrant a full blog post. These are mostly things I learn by pairing with
88smart people at [ Hashrocket] ( http://hashrocket.com/ ) .
99
10- _ 503  TILs and counting..._ 
10+ _ 504  TILs and counting..._ 
1111
1212--- 
1313
@@ -220,6 +220,7 @@ _503 TILs and counting..._
220220-  [ Aggregate A Column Into An Array] ( postgres/aggregate-a-column-into-an-array.md ) 
221221-  [ Assumed Radius Of The Earth] ( postgres/assumed-radius-of-the-earth.md ) 
222222-  [ Auto Expanded Display] ( postgres/auto-expanded-display.md ) 
223+ -  [ Between Symmetric] ( postgres/between-symmetric.md ) 
223224-  [ Change The Current Directory For psql] ( postgres/change-the-current-directory-for-psql.md ) 
224225-  [ Checking Inequality] ( postgres/checking-inequality.md ) 
225226-  [ Checking The Type Of A Value] ( postgres/checking-the-type-of-a-value.md ) 
Original file line number Diff line number Diff line change 1+ # Between Symmetric  
2+ 
3+ PostgreSQL's ` between `  construct allows you to make a comparison _ between_ 
4+ two values (numbers, timestamps, etc.).
5+ 
6+ ``` sql 
7+ >  select  *  from  generate_series(1 ,10 ) as  numbers(a) where  numbers .a  between 3  and  6 ;
8+  a
9+ -- -
10+  3 
11+  4 
12+  5 
13+  6 
14+ ``` 
15+ 
16+ If you supply an empty range by using the larger of the two values first, an
17+ empty set will result.
18+ 
19+ ``` sql 
20+ >  select  *  from  generate_series(1 ,10 ) as  numbers(a) where  numbers .a  between 6  and  3 ;
21+  a
22+ -- -
23+ ``` 
24+ 
25+ Tacking ` symmetric `  onto the ` between `  construct is one way to avoid this
26+ issue.
27+ 
28+ ``` sql 
29+ >  select  *  from  generate_series(1 ,10 ) as  numbers(a) where  numbers .a  between symmetric 6  and  3 ;
30+  a
31+ -- -
32+  3 
33+  4 
34+  5 
35+  6 
36+ ``` 
37+ 
38+ >  BETWEEN SYMMETRIC is the same as BETWEEN except there is no requirement
39+ >  that the argument to the left of AND be less than or equal to the argument
40+ >  on the right. If it is not, those two arguments are automatically swapped,
41+ >  so that a nonempty range is always implied.
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments