Home Explore Blog CI



postgresql

22th chunk of `doc/src/sgml/catalogs.sgml`
20d206a007b965f7264e9e698d10c9f04bddb8aa0bff29bd0000000100000fa7
 role="catalog_table_entry"><para role="column_definition">
       <structfield>casttarget</structfield> <type>oid</type>
       (references <link linkend="catalog-pg-type"><structname>pg_type</structname></link>.<structfield>oid</structfield>)
      </para>
      <para>
       OID of the target data type
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>castfunc</structfield> <type>oid</type>
       (references <link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.<structfield>oid</structfield>)
      </para>
      <para>
       The OID of the function to use to perform this cast.  Zero is
       stored if the cast method doesn't require a function.
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>castcontext</structfield> <type>char</type>
      </para>
      <para>
       Indicates what contexts the cast can be invoked in.
       <literal>e</literal> means only as an explicit cast (using
       <literal>CAST</literal> or <literal>::</literal> syntax).
       <literal>a</literal> means implicitly in assignment
       to a target column, as well as explicitly.
       <literal>i</literal> means implicitly in expressions, as well as the
       other cases.
      </para></entry>
     </row>

     <row>
      <entry role="catalog_table_entry"><para role="column_definition">
       <structfield>castmethod</structfield> <type>char</type>
      </para>
      <para>
       Indicates how the cast is performed.
       <literal>f</literal> means that the function specified in the <structfield>castfunc</structfield> field is used.
       <literal>i</literal> means that the input/output functions are used.
       <literal>b</literal> means that the types are binary-coercible, thus no conversion is required.
      </para></entry>
     </row>
    </tbody>
   </tgroup>
  </table>

  <para>
   The cast functions listed in <structname>pg_cast</structname> must
   always take the cast source type as their first argument type, and
   return the cast destination type as their result type.  A cast
   function can have up to three arguments.  The second argument,
   if present, must be type <type>integer</type>; it receives the type
   modifier associated with the destination type, or -1
   if there is none.  The third argument,
   if present, must be type <type>boolean</type>; it receives <literal>true</literal>
   if the cast is an explicit cast, <literal>false</literal> otherwise.
  </para>

  <para>
   It is legitimate to create a <structname>pg_cast</structname> entry
   in which the source and target types are the same, if the associated
   function takes more than one argument.  Such entries represent
   <quote>length coercion functions</quote> that coerce values of the type
   to be legal for a particular type modifier value.
  </para>

  <para>
   When a <structname>pg_cast</structname> entry has different source and
   target types and a function that takes more than one argument, it
   represents converting from one type to another and applying a length
   coercion in a single step.  When no such entry is available, coercion
   to a type that uses a type modifier involves two steps, one to
   convert between data types and a second to apply the modifier.
  </para>
 </sect1>

 <sect1 id="catalog-pg-class">
  <title><structname>pg_class</structname></title>

  <indexterm zone="catalog-pg-class">
   <primary>pg_class</primary>
  </indexterm>

  <para>
   The catalog <structname>pg_class</structname> describes tables and
   other objects that have columns or are otherwise similar to a
   table.  This includes indexes (but see also <link
   linkend="catalog-pg-index"><structname>pg_index</structname></link>),
   sequences (but see also <link
   linkend="catalog-pg-sequence"><structname>pg_sequence</structname></link>),
   views, materialized views, composite

Title: pg_cast Columns and Cast Function Requirements
Summary
This section details the remaining columns of the pg_cast catalog, explaining the cast context (explicit, assignment, or implicit) and the cast method (function, I/O functions, or binary-coercible). It further specifies the requirements for cast functions listed in pg_cast, including argument types and return types. The section also discusses cases where source and target types are the same, indicating 'length coercion functions,' and situations where a single pg_cast entry can combine type conversion and length coercion.