Home Explore Blog CI



postgresql

64th chunk of `doc/src/sgml/libpq.sgml`
b00762c128a55957a6b7f5a8ea8db00a9ddeda4c94b140c30000000100000fa9
 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 returned  by  <xref linkend="libpq-PQgetvalue"/> points
       to storage that is part of the <structname>PGresult</structname>
       structure.  One should not modify the data it points to, and one
       must explicitly copy the data into other storage if it is to be
       used past the lifetime of the  <structname>PGresult</structname>
       structure itself.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQgetisnull">
     <term><function>PQgetisnull</function><indexterm
     ><primary>PQgetisnull</primary></indexterm><indexterm
     ><primary>null value</primary><secondary sortas="libpq">in libpq</secondary></indexterm></term>

     <listitem>
      <para>
       Tests a field for a null value.  Row and column numbers start
       at 0.
<synopsis>
int PQgetisnull(const PGresult *res,
                int row_number,
                int column_number);
</synopsis>
      </para>

      <para>
       This function returns  1 if the field is null and 0 if it
       contains a non-null value.  (Note that
       <xref linkend="libpq-PQgetvalue"/> will return an empty string,
       not a null pointer, for a null field.)
      </para>
     </listitem>
    </varlistentry>

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

     <listitem>
      <para>
       Returns the actual length of a field value in bytes.  Row and
       column numbers start at 0.
<synopsis>
int PQgetlength(const PGresult *res,
                int row_number,
                int column_number);
</synopsis>
      </para>

      <para>
       This is the actual data length for the particular data value,
       that is, the size of the object pointed to by
       <xref linkend="libpq-PQgetvalue"/>.  For text data format this is
       the same as <function>strlen()</function>.  For binary format this is
       essential information.  Note that one should <emphasis>not</emphasis>
       rely on <xref linkend="libpq-PQfsize"/> to obtain the actual data
       length.
      </para>
     </listitem>
    </varlistentry>

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

     <listitem>
      <para>
       Returns the number of parameters of a prepared statement.
<synopsis>
int PQnparams(const PGresult *res);
</synopsis>
      </para>

      <para>
       This function is only useful when inspecting the result of
       <xref linkend="libpq-PQdescribePrepared"/>.  For other types of results it
       will return zero.
      </para>
     </listitem>
    </varlistentry>

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

     <listitem>
      <para>
       Returns the data type of the indicated statement parameter.
       Parameter numbers start at 0.
<synopsis>
Oid PQparamtype(const

Title: libpq Functions for Checking Nulls, Getting Length, and Prepared Statement Parameters
Summary
This section describes libpq functions for handling data within a PGresult. `PQgetisnull` checks if a field value is NULL. `PQgetlength` retrieves the actual length of a field's data in bytes. `PQnparams` returns the number of parameters in a prepared statement result. The returned pointer of PQgetvalue should be copied if it needs to be used past the PGresult struct.