Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/intagg.sgml`
6c3f0cac589adbf9f88066fbde34ed3d779f00773e47fbbc0000000100000882
<!-- doc/src/sgml/intagg.sgml -->

<sect1 id="intagg" xreflabel="intagg">
 <title>intagg &mdash; integer aggregator and enumerator</title>

 <indexterm zone="intagg">
  <primary>intagg</primary>
 </indexterm>

 <para>
  The <filename>intagg</filename> module provides an integer aggregator and an
  enumerator.  <filename>intagg</filename> is now obsolete, because there
  are built-in functions that provide a superset of its capabilities.
  However, the module is still provided as a compatibility wrapper around
  the built-in functions.
 </para>

 <sect2 id="intagg-functions">
  <title>Functions</title>

 <indexterm>
  <primary>int_array_aggregate</primary>
 </indexterm>

 <indexterm>
  <primary>array_agg</primary>
 </indexterm>

 <para>
  The aggregator is an aggregate function
  <function>int_array_aggregate(integer)</function>
  that produces an integer array
  containing exactly the integers it is fed.
  This is a wrapper around <function>array_agg</function>,
  which does the same thing for any array type.
 </para>

 <indexterm>
  <primary>int_array_enum</primary>
 </indexterm>

 <para>
  The enumerator is a function
  <function>int_array_enum(integer[])</function>
  that returns <type>setof integer</type>.  It is essentially the reverse
  operation of the aggregator: given an array of integers, expand it
  into a set of rows.  This is a wrapper around <function>unnest</function>,
  which does the same thing for any array type.
 </para>

 </sect2>

 <sect2 id="intagg-samples">
  <title>Sample Uses</title>

  <para>
   Many database systems have the notion of a many to many table. Such a table
   usually sits between two indexed tables, for example:

<programlisting>
CREATE TABLE left_table  (id INT PRIMARY KEY, ...);
CREATE TABLE right_table (id INT PRIMARY KEY, ...);
CREATE TABLE many_to_many(id_left  INT REFERENCES left_table,
                          id_right INT REFERENCES right_table);
</programlisting>

  It is typically used like this:

<programlisting>
SELECT right_table.*
FROM right_table JOIN many_to_many ON (right_table.id = many_to_many.id_right)
WHERE many_to_many.id_left = <replaceable>item</replaceable>;
</programlisting>

Title: Integer Aggregator and Enumerator Module
Summary
The intagg module provides an integer aggregator and enumerator, although it is now obsolete due to built-in functions offering the same capabilities, and includes functions such as int_array_aggregate and int_array_enum for array aggregation and enumeration.