Re: [GENERAL] insert iff !exist

From: Karl DeBisschop <kdebisschop(at)spaceheater(dot)infoplease(dot)com>
To: prlw1(at)cam(dot)ac(dot)uk
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] insert iff !exist
Date: 1999-04-11 11:34:11
Message-ID: 199904111134.HAA00061@spaceheater.infoplease.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vince Vielhaber 1999-04-11 15:10:08 RE: cant connect
Previous Message Patrick M. Landry 1999-04-10 20:04:52 bug report