Give the full syntax rules for subscripting and field selection in the
authorTom Lane
Tue, 4 Nov 2003 19:18:15 +0000 (19:18 +0000)
committerTom Lane
Tue, 4 Nov 2003 19:18:15 +0000 (19:18 +0000)
proper place, namely the syntax discussion of value expressions.

doc/src/sgml/syntax.sgml

index dc77f0abc65f2123691c41dc531688b11ebf6625..b780fce083b59118a188b56554920e196fc1017b 100644 (file)
@@ -1,5 +1,5 @@
 
 
 
@@ -185,7 +185,7 @@ UPDATE "my_table" SET "a" = 5;
 
    
     Quoted identifiers can contain any character other than a double
-    quote itself.  To include a double quote, write two double quotes.
+    quote itself.  (To include a double quote, write two double quotes.)
     This allows constructing table or column names that would
     otherwise not be possible, such as ones containing spaces or
     ampersands.  The length limitation still applies.
@@ -449,7 +449,7 @@ CAST ( 'string' AS type )
    
 
    
-    An operator is a sequence of up to NAMEDATALEN-1
+    An operator name is a sequence of up to NAMEDATALEN-1
     (63 by default) characters from the following list:
 
 + - * / < > = ~ ! @ # % ^ & | ` ?
@@ -855,6 +855,18 @@ SELECT 3 OPERATOR(pg_catalog.+) 4;
      
     
 
+    
+     
+      A subscripted expression.
+     
+    
+
+    
+     
+      A field selection expression.
+     
+    
+
     
      
       An operator invocation.
@@ -928,31 +940,18 @@ SELECT 3 OPERATOR(pg_catalog.+) 4;
 
 correlation.columnname
 
-    or
-
-correlation.columnname[subscript]
-
-    (Here, the brackets [ ] are meant to appear literally.)
    
 
    
     correlation is the name of a
-    table (possibly qualified), or an alias for a table defined by means of a
-    FROM clause, or 
+    table (possibly qualified with a schema name), or an alias for a table
+    defined by means of a FROM clause, or one of
     the key words NEW or OLD.
     (NEW and OLD can only appear in rewrite rules,
     while other correlation names can be used in any SQL statement.)
     The correlation name and separating dot may be omitted if the column name
     is unique across all the tables being used in the current query.  (See also .)
    
-
-   
-    If column is of an array type, then the
-    optional subscript selects a specific
-    element or elements in the array.  If no subscript is provided, then the
-    whole array is selected.  (See  for more about
-    arrays.)
-   
   
 
   
@@ -995,6 +994,81 @@ CREATE FUNCTION dept(text) RETURNS dept
    
   
 
+  
+   Subscripts
+
+   
+    subscript
+   
+
+   
+    If an expression yields a value of an array type, then a specific
+    element of the array value can be extracted by writing
+
+expression[subscript]
+
+    or multiple adjacent elements (an array slice) can be extracted
+    by writing
+
+expression[lower_subscript:upper_subscript]
+
+    (Here, the brackets [ ] are meant to appear literally.)
+    Each subscript is itself an expression,
+    which must yield an integer value.
+   
+
+   
+    In general the array expression must be
+    parenthesized, but the parentheses may be omitted when the expression
+    to be subscripted is just a column reference or positional parameter.
+    Also, multiple subscripts can be concatenated when the original array
+    is multi-dimensional.
+    For example,
+
+
+mytable.arraycolumn[4]
+mytable.two_d_column[17][34]
+$1[10:42]
+(arrayfunction(a,b))[42]
+
+
+    The parentheses in the last example are required.
+    See  for more about arrays.
+   
+  
+
+  
+   Field Selection
+
+   
+    field selection
+   
+
+   
+    If an expression yields a value of a composite type (row type), then a
+    specific field of the row can be extracted by writing
+
+expression.fieldname
+
+   
+
+   
+    In general the row expression must be
+    parenthesized, but the parentheses may be omitted when the expression
+    to be selected from is just a table reference or positional parameter.
+    For example,
+
+
+mytable.mycolumn
+$1.somecolumn
+(rowfunction(a,b)).col3
+
+
+    (Thus, a qualified column reference is actually just a special case
+    of the field selection syntax.)
+   
+  
+
   
    Operator Invocations
 
@@ -1013,7 +1087,7 @@ CREATE FUNCTION dept(text) RETURNS dept
     where the operator token follows the syntax
     rules of , or is one of the
     key words ANDOR, and
-    NOT, or is a qualified operator name
+    NOT, or is a qualified operator name in the form
 
 OPERATOR(schema.operatorname)
 
@@ -1078,7 +1152,7 @@ sqrt(2)
 
 
     where aggregate_name is a previously
-    defined aggregate (possibly a qualified name), and
+    defined aggregate (possibly qualified with a schema name), and
     expression is 
     any value expression that does not itself contain an aggregate
     expression.