pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedReplace into...?
4+ messages / 3 participants
[nested] [flat]
* Replace into...?
@ 2001-03-27 19:30 Diehl, Jeffrey <jdiehl@sandia.gov>
2001-03-27 20:04 ` Re: Replace into...? Tom Lane <tgl@sss.pgh.pa.us>
2001-03-27 20:09 ` Re: Replace into...? Peter Eisentraut <peter_e@gmx.net>
0 siblings, 2 replies; 4+ messages in thread
From: Diehl, Jeffrey @ 2001-03-27 19:30 UTC (permalink / raw)
To: pgsql-sql
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.
Thanx in advance,
Mike Diehl,
Network Monitoring Tool Devl.
284-3137
jdiehl@sandia.gov
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Replace into...?
2001-03-27 19:30 Replace into...? Diehl, Jeffrey <jdiehl@sandia.gov>
@ 2001-03-27 20:04 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 4+ messages in thread
From: Tom Lane @ 2001-03-27 20:04 UTC (permalink / raw)
To: Diehl, Jeffrey <jdiehl@sandia.gov>; +Cc: pgsql-sql
"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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Replace into...?
2001-03-27 19:30 Replace into...? Diehl, Jeffrey <jdiehl@sandia.gov>
@ 2001-03-27 20:09 ` Peter Eisentraut <peter_e@gmx.net>
1 sibling, 0 replies; 4+ messages in thread
From: Peter Eisentraut @ 2001-03-27 20:09 UTC (permalink / raw)
To: Diehl, Jeffrey <jdiehl@sandia.gov>; +Cc: pgsql-sql
Diehl, Jeffrey 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...
begin transaction;
update ...
<if zero rows>
insert ...
<endif>
commit;
or some permutation thereof. If you need to do a lot of this, writing a
PL/pgSQL function might be worthwhile.
--
Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/
^ permalink raw reply [nested|flat] 4+ messages in thread
* RE: Replace into...?
@ 2001-03-27 20:28 Diehl, Jeffrey <jdiehl@sandia.gov>
0 siblings, 0 replies; 4+ messages in thread
From: Diehl, Jeffrey @ 2001-03-27 20:28 UTC (permalink / raw)
To: 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
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2001-03-27 20:28 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-27 19:30 Replace into...? Diehl, Jeffrey <jdiehl@sandia.gov>
2001-03-27 20:04 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-03-27 20:09 ` Peter Eisentraut <peter_e@gmx.net>
2001-03-27 20:28 RE: Replace into...? Diehl, Jeffrey <jdiehl@sandia.gov>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox