Home Explore Blog CI



postgresql

63th chunk of `doc/src/sgml/libpq.sgml`
cff43d5f55bf7b062da7832cb7bc7b0d7aa9e7e20d91ad5e0000000100000fa1
 <productname>PostgreSQL</productname>
       installation's <filename>include</filename> directory.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQfmod">
     <term><function>PQfmod</function><indexterm><primary>PQfmod</primary></indexterm></term>

     <listitem>
      <para>
       Returns  the type modifier of the column associated with the
       given column number.  Column numbers start at 0.
<synopsis>
int PQfmod(const PGresult *res,
           int column_number);
</synopsis>
      </para>

      <para>
       The interpretation of modifier values is type-specific; they
       typically indicate precision or size limits.  The value -1 is
       used to indicate <quote>no information available</quote>.  Most data
       types do not use modifiers, in which case the value is always
       -1.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQfsize">
     <term><function>PQfsize</function><indexterm><primary>PQfsize</primary></indexterm></term>

     <listitem>
      <para>
       Returns  the  size  in bytes of the column associated with the
       given column number.  Column numbers start at 0.
<synopsis>
int PQfsize(const PGresult *res,
            int column_number);
</synopsis>
      </para>

      <para>
       <xref linkend="libpq-PQfsize"/> returns the space allocated for this column
       in a database row, in other words the size of the server's
       internal representation of the data type.  (Accordingly, it is
       not really very useful to clients.) A negative value indicates
       the data type is variable-length.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQbinaryTuples">
     <term><function>PQbinaryTuples</function><indexterm><primary>PQbinaryTuples</primary></indexterm></term>

     <listitem>
      <para>
       Returns 1 if the <structname>PGresult</structname> contains binary data
       and 0 if it contains text data.
<synopsis>
int PQbinaryTuples(const PGresult *res);
</synopsis>
      </para>

      <para>
       This function is deprecated (except for its use in connection with
       <command>COPY</command>), because it is possible for a single
       <structname>PGresult</structname> to contain text data in some columns and
       binary data in others.  <xref linkend="libpq-PQfformat"/> is preferred.
       <xref linkend="libpq-PQbinaryTuples"/> returns 1 only if all columns of the
       result are binary (format 1).
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQgetvalue">
     <term><function>PQgetvalue</function><indexterm><primary>PQgetvalue</primary></indexterm></term>

     <listitem>
      <para>
       Returns a single field value of one row of a
       <structname>PGresult</structname>.  Row and column numbers start
       at 0.  The caller should not free the result directly.  It will
       be freed when the associated <structname>PGresult</structname> handle is
       passed to <xref linkend="libpq-PQclear"/>.
<synopsis>
char *PQgetvalue(const PGresult *res,
                 int row_number,
                 int column_number);
</synopsis>
      </para>

      <para>
       For data in text format, the value returned by
       <xref linkend="libpq-PQgetvalue"/> is a null-terminated character
       string  representation of the field value.  For data in binary
       format, the value is in the binary representation determined by
       the data type's <function>typsend</function> and <function>typreceive</function>
       functions.  (The value is actually followed by a zero byte in
       this case too, but that is not ordinarily useful, since the
       value is likely to contain embedded nulls.)
      </para>

      <para>
       An empty string is returned if the field value is null.  See
       <xref linkend="libpq-PQgetisnull"/> to distinguish null values from
       empty-string values.
      </para>

      <para>
       The pointer

Title: More Column Information, Binary Data Check, and Retrieving Field Values in libpq
Summary
This section details more libpq functions for column information, checking binary data, and retrieving field values. It covers `PQfmod` (to get the column's type modifier), `PQfsize` (to get the column's size in bytes), `PQbinaryTuples` (deprecated function to check if the entire result is binary), and `PQgetvalue` (to get a single field value from a result). It describes what each function returns, including special values, and how to interpret the results, with notes on data formats and handling null values.