Re: Number of updated rows with LibPQ - Mailing list pgsql-general

From Daniel Verite
Subject Re: Number of updated rows with LibPQ
Date
Msg-id c0bc0696-02b0-41b8-8e1c-75cb726e78de@manitou-mail.org
Whole thread Raw
In response to Re: Number of updated rows with LibPQ  (Laurenz Albe <laurenz.albe@cybertec.at>)
Responses Re: Number of updated rows with LibPQ
List pgsql-general
    Laurenz Albe wrote:

> > Or is there a libpq API on PGresult that would allow to get the type
> > of statement the result is from?
>
> The command tag is not what you look at.

Yet that's what psql does. from PrintQueryResult():

    /* if it's INSERT/UPDATE/DELETE RETURNING, also print status */
    if (last || pset.show_all_results)
    {
        cmdstatus = PQcmdStatus(result);
        if (strncmp(cmdstatus, "INSERT", 6) == 0 ||
            strncmp(cmdstatus, "UPDATE", 6) == 0 ||
            strncmp(cmdstatus, "DELETE", 6) == 0)
            PrintQueryStatus(result, printStatusFout);
    }



> You simply check the result from an INSERT statement.  If it is
> PGRES_TUPLES_OK, it must have been INSERT ... RETRUNING.

Or a SELECT, or an UPDATE RETURNING, or a DELETE RETURNING.
The code still need to look at PQcmdStatus() to learn which kind it is,
if it needs to know this.


Best regards,
--
Daniel Vérité
https://postgresql.verite.pro/
Twitter: @DanielVerite



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: [libpq] OIDs of extension types? Of custom types?
Next
From: Tom Lane
Date:
Subject: Re: How to return argument data type from sql function