RE: Replace into...? - Mailing list pgsql-sql

From Diehl, Jeffrey
Subject RE: Replace into...?
Date
Msg-id B51F0C636E578A4E832D3958690CD73E0130BE89@es04snlnt
Whole thread Raw
In response to Replace into...?  ("Diehl, Jeffrey" <jdiehl@sandia.gov>)
List pgsql-sql
Replace into does an insert by default.  If however, there is already a
record which would cause a unique index collision, then mysql does an update
on that record.  I want to prevent my application from having to do all of
that bookkeeping.

Peter Eisentraut has suggested:
begin transaction;
update ...
<if zero rows> insert ...
<endif>
commit;

This seems like a good way to go.  He suggested that I write a PL/pgSQL
function to do the work.  I really don't have time to climb the learning
curve on this so I might just write a perl module to do it, and a few other
things, for me.

Thanx for your help.

If there is AN EVEN EASIER way, please let me know.

Mike Diehl,
Network Monitoring Tool Devl.
284-3137
jdiehl@sandia.gov



> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Sent: March 27, 2001 1:04 PM
> To: Diehl, Jeffrey
> Cc: pgsql-sql@postgresql.org
> Subject: Re: [SQL] Replace into...?
> 
> 
> "Diehl, Jeffrey" <jdiehl@sandia.gov> writes:
> > I'm in the process of migrating a database and application 
> suite from mysql
> > to postgresql.  The problem is that I've used
> > mysql's "replace into..." quite frequently...
> 
> > Does anyone know of a "clean" way to implement this feature 
> in postgresql?
> > I really don't want my applications to have to know what 
> indexes are in
> > place for a given table.
> 
> I'm confused.  What does "replace into" have to do with having to know
> what indexes are in place?
> 
>             regards, tom lane
> 



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Replace into...?
Next
From: Forest Wilkinson
Date:
Subject: possible row locking bug in 7.0.3 & 7.1