doc: More documentation on regular expressions and SQL standard
authorPeter Eisentraut
Mon, 20 Dec 2021 09:12:25 +0000 (10:12 +0100)
committerPeter Eisentraut
Mon, 20 Dec 2021 09:36:44 +0000 (10:36 +0100)
Reviewed-by: Gilles Darold
Discussion: https://www.postgresql.org/message-id/b7988566-daa2-80ed-2fdc-6f6630462d26@enterprisedb.com

doc/src/sgml/func.sgml
src/backend/catalog/sql_features.txt

index 5801299b2778d6275856be884f1de7e2e9633b30..e58efce5865aee60335dd379e03de041955512ea 100644 (file)
@@ -7353,10 +7353,26 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
 
 
    
-   Differences from <span class="marked">XQuery (<literal>LIKE_REGEX</literal>)</span>
+   Differences from <span class="marked">SQL Standard and XQuery</span>
 
    
-    LIKE_REGEX
+    LIKE_REGEX
+   
+
+   
+    OCCURRENCES_REGEX
+   
+
+   
+    POSITION_REGEX
+   
+
+   
+    SUBSTRING_REGEX
+   
+
+   
+    TRANSLATE_REGEX
    
 
    
@@ -7364,16 +7380,75 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
    
 
     
-     Since SQL:2008, the SQL standard includes
-     a LIKE_REGEX operator that performs pattern
+     Since SQL:2008, the SQL standard includes regular expression operators
+     and functions that performs pattern
      matching according to the XQuery regular expression
-     standard.  PostgreSQL does not yet
-     implement this operator, but you can get very similar behavior using
-     the regexp_match() function, since XQuery
-     regular expressions are quite close to the ARE syntax described above.
+     standard:
+     
+      LIKE_REGEX
+      OCCURRENCES_REGEX
+      POSITION_REGEX
+      SUBSTRING_REGEX
+      TRANSLATE_REGEX
+     
+     PostgreSQL does not currently implement these
+     operators and functions.  You can get approximately equivalent
+     functionality in each case as shown in 
+     linkend="functions-regexp-sql-table"/>.  (Various optional clauses on
+     both sides have been omitted in this table.)
+    
+
+    
+     Regular Expression Functions Equivalencies
+
+     
+      
+       
+        SQL standard
+        PostgreSQL
+       
+      
+
+      
+       
+        string LIKE_REGEX pattern
+        regexp_like(stringpattern) or string ~ pattern
+       
+
+       
+        OCCURRENCES_REGEX(pattern IN string
+        regexp_count(stringpattern)
+       
+
+       
+        POSITION_REGEX(pattern IN string
+        regexp_instr(stringpattern)
+       
+
+       
+        SUBSTRING_REGEX(pattern IN string
+        regexp_substr(stringpattern)
+       
+
+       
+        TRANSLATE_REGEX(pattern IN string WITH replacement
+        regexp_replace(stringpatternreplacement)
+       
+      
+     
+    
+
+    
+     Regular expression functions similar to those provided by PostgreSQL are
+     also available in a number of other SQL implementations, whereas the
+     SQL-standard functions are not as widely implemented.  Some of the
+     details of the regular expression syntax will likely differ in each
+     implementation.
     
 
     
+     The SQL-standard operators and functions use XQuery regular expressions,
+     which are quite close to the ARE syntax described above.
      Notable differences between the existing POSIX-based
      regular-expression feature and XQuery regular expressions include:
 
index 9f424216e26cff0a8ee7912efd9fe49b7347421f..b8a78f4d4190070cf4e7038a8be88b05318773a8 100644 (file)
@@ -323,11 +323,11 @@ F821  Local table references          NO
 F831   Full cursor update          NO  
 F831   Full cursor update  01  Updatable scrollable cursors    NO  
 F831   Full cursor update  02  Updatable ordered cursors   NO  
-F841   LIKE_REGEX predicate            NO  
-F842   OCCURRENCES_REGEX function          NO  
-F843   POSITION_REGEX function         NO  
-F844   SUBSTRING_REGEX function            NO  
-F845   TRANSLATE_REGEX function            NO  
+F841   LIKE_REGEX predicate            NO  consider regexp_like()
+F842   OCCURRENCES_REGEX function          NO  consider regexp_matches()
+F843   POSITION_REGEX function         NO  consider regexp_instr()
+F844   SUBSTRING_REGEX function            NO  consider regexp_substr()
+F845   TRANSLATE_REGEX function            NO  consider regexp_replace()
 F846   Octet support in regular expression operators           NO  
 F847   Nonconstant regular expressions         NO  
 F850   Top-level  in            YES