Home Explore Blog CI



postgresql

6th chunk of `doc/src/sgml/ref/create_type.sgml`
ff26980365143b4522d52abaf67e87c8326f3141117f47e30000000100000fa2
 <replaceable class="parameter">type_modifier_input_function</replaceable>
   is passed the declared modifier(s) in the form of a <type>cstring</type>
   array.  It must check the values for validity (throwing an error if they
   are wrong), and if they are correct, return a single non-negative
   <type>integer</type> value that will be stored as the column <quote>typmod</quote>.
   Type modifiers will be rejected if the type does not have a
   <replaceable class="parameter">type_modifier_input_function</replaceable>.
   The <replaceable class="parameter">type_modifier_output_function</replaceable>
   converts the internal integer typmod value back to the correct form for
   user display.  It must return a <type>cstring</type> value that is the exact
   string to append to the type name; for example <type>numeric</type>'s
   function might return <literal>(30,2)</literal>.
   It is allowed to omit the
   <replaceable class="parameter">type_modifier_output_function</replaceable>,
   in which case the default display format is just the stored typmod integer
   value enclosed in parentheses.
  </para>

  <para>
   The optional <replaceable class="parameter">analyze_function</replaceable>
   performs type-specific statistics collection for columns of the data type.
   By default, <command>ANALYZE</command> will attempt to gather statistics using
   the type's <quote>equals</quote> and <quote>less-than</quote> operators, if there
   is a default b-tree operator class for the type.  For non-scalar types
   this behavior is likely to be unsuitable, so it can be overridden by
   specifying a custom analysis function.  The analysis function must be
   declared to take a single argument of type <type>internal</type>, and return
   a <type>boolean</type> result.  The detailed API for analysis functions appears
   in <filename>src/include/commands/vacuum.h</filename>.
  </para>

  <para>
   The optional <replaceable class="parameter">subscript_function</replaceable>
   allows the data type to be subscripted in SQL commands.  Specifying this
   function does not cause the type to be considered a <quote>true</quote>
   array type; for example, it will not be a candidate for the result type
   of <literal>ARRAY[]</literal> constructs.  But if subscripting a value
   of the type is a natural notation for extracting data from it, then
   a <replaceable class="parameter">subscript_function</replaceable> can
   be written to define what that means.  The subscript function must be
   declared to take a single argument of type <type>internal</type>, and
   return an <type>internal</type> result, which is a pointer to a struct
   of methods (functions) that implement subscripting.
   The detailed API for subscript functions appears
   in <filename>src/include/nodes/subscripting.h</filename>.
   It may also be useful to read the array implementation
   in <filename>src/backend/utils/adt/arraysubs.c</filename>,
   or the simpler code
   in <filename>contrib/hstore/hstore_subs.c</filename>.
   Additional information appears in
   <xref linkend="sql-createtype-array"/> below.
  </para>

  <para>
   While the details of the new type's internal representation are only
   known to the I/O functions and other functions you create to work with
   the type, there are several properties of the internal representation
   that must be declared to <productname>PostgreSQL</productname>.
   Foremost of these is
   <replaceable class="parameter">internallength</replaceable>.
   Base data types can be fixed-length, in which case
   <replaceable class="parameter">internallength</replaceable> is a
   positive integer, or variable-length, indicated by setting
   <replaceable class="parameter">internallength</replaceable>
   to <literal>VARIABLE</literal>.  (Internally, this is represented
   by setting <literal>typlen</literal> to -1.)  The internal representation of all
   variable-length types must start with a 4-byte integer giving the total
   length of this value of

Title: CREATE TYPE - Type Modifiers, ANALYZE Function, Subscripting, and Internal Length
Summary
The text describes the optional `type_modifier_input_function` and `type_modifier_output_function`, which handle type modifiers. The `analyze_function` allows type-specific statistics collection, overriding the default behavior of `ANALYZE`. The `subscript_function` enables subscripting of the data type in SQL commands. Finally, it mentions that the `internallength` parameter declares whether the data type is fixed-length or variable-length.