Home Explore Blog CI



postgresql

8th chunk of `doc/src/sgml/array.sgml`
1a05907f449f053c79184d84506786544da973818da130fc0000000100000a37
 array_position
----------------
              2
(1 row)

SELECT array_positions(ARRAY[1, 4, 3, 1, 3, 4, 2, 1], 1);
 array_positions
-----------------
 {1,4,8}
(1 row)
</programlisting>
 </para>

 <tip>
  <para>
   Arrays are not sets; searching for specific array elements
   can be a sign of database misdesign.  Consider
   using a separate table with a row for each item that would be an
   array element.  This will be easier to search, and is likely to
   scale better for a large number of elements.
  </para>
 </tip>
 </sect2>

 <sect2 id="arrays-io">
  <title>Array Input and Output Syntax</title>

  <indexterm>
   <primary>array</primary>
   <secondary>I/O</secondary>
  </indexterm>

  <para>
   The external text representation of an array value consists of items that
   are interpreted according to the I/O conversion rules for the array's
   element type, plus decoration that indicates the array structure.
   The decoration consists of curly braces (<literal>{</literal> and <literal>}</literal>)
   around the array value plus delimiter characters between adjacent items.
   The delimiter character is usually a comma (<literal>,</literal>) but can be
   something else: it is determined by the <literal>typdelim</literal> setting
   for the array's element type.  Among the standard data types provided
   in the <productname>PostgreSQL</productname> distribution, all use a comma,
   except for type <type>box</type>, which uses a semicolon (<literal>;</literal>).
   In a multidimensional array, each dimension (row, plane,
   cube, etc.) gets its own level of curly braces, and delimiters
   must be written between adjacent curly-braced entities of the same level.
  </para>

  <para>
   The array output routine will put double quotes around element values
   if they are empty strings, contain curly braces, delimiter characters,
   double quotes, backslashes, or white space, or match the word
   <literal>NULL</literal>.  Double quotes and backslashes
   embedded in element values will be backslash-escaped.  For numeric
   data types it is safe to assume that double quotes will never appear, but
   for textual data types one should be prepared to cope with either the presence
   or absence of quotes.
  </para>

  <para>
   By default, the lower bound index value of an array's dimensions is
   set to one.  To represent arrays with other lower bounds, the array
   subscript ranges can be specified explicitly before writing the
   array contents.
   This decoration consists of square brackets (<literal>[]</literal>)
   around each array dimension's lower and upper bounds, with

Title: Array Input and Output Syntax
Summary
The external text representation of an array value in PostgreSQL consists of items separated by delimiters, typically commas, and enclosed in curly braces, with special handling for empty strings, curly braces, and other special characters, and optional specification of array subscript ranges using square brackets.