Search Postgresql Archives

Re: Number of updated rows with LibPQ

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



	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






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux