Re: [GENERAL] insert iff !exist - Mailing list pgsql-general

From Karl DeBisschop
Subject Re: [GENERAL] insert iff !exist
Date
Msg-id 199904111134.HAA00061@spaceheater.infoplease.com
Whole thread Raw
In response to insert iff !exist  ("Patrick Welche" <prlw1@newn.cam.ac.uk>)
List pgsql-general
> How can you
>
> if(update row fails because doesn't exist, ie. returns 0)then(insert row)

Depends on what interface you are using.

In perl DBI, the return value of the a $dbh->do("update...") should be
the nomber of rows inserted. Same with doing a sequence of
    $sth=$dbh->prepare("updated...");
    $rc=$sth->execute;
$rc will be the number of rows updated.  Then just do the insert if $rc is 0.

In php, you use the function pg_NumRows.

In libpg, the number of rows is obtained from PGntuples after the update;



Karl

pgsql-general by date:

Previous
From: "Patrick M. Landry"
Date:
Subject: bug report
Next
From: Vince Vielhaber
Date:
Subject: RE: cant connect