From: Josh Berkus <josh@agliodbs.com>
To: Diehl, Jeffrey <jdiehl@sandia.gov>
Cc: 'pgsql-sql@postgreSQL.org' <pgsql-sql@postgreSQL.org>
Subject: Re: mysql's "replace into..."
Date: Wed, 28 Feb 2001 11:56:36 -0800
Message-ID: <3A9D57F4.E85E3E6E@agliodbs.com> (raw)
References: <B51F0C636E578A4E832D3958690CD73E0130BE49@es04snlnt>
Jeff,
> I'm in the process of migrating a production database and related
> applicatoins from mysql to postgresql. I've just not been very impressed
> with mysql's stability, that is I'm trying to make my phone stop ringing.
Surprising. I have a number of gripes with MySQL (of which REPLACE INTO
is one), but stability isn't one of them.
> However, when I wrote the applications, I took free advantage of mysql's
> replace into feature which behaves like a smart insert that inserts new
> records or updates old records. I'm using perl DBI and need to figure out a
> good way to migrate this to postgresql.
>
> Any ideas?
Well, you have two choices. One is to get used to standard SQL and use
the SQL I will expound below. The other is to actually hire a C
programmer to modify the PostgreSQL source to support Replace Into.
Great Bridge might be willing to help.
Regardless, your SQL functionality requires the following steps:
1. All tables involved *must* have primary keys. I reccommend against
using the OID for this purpose for several reasons; see the archives for
a discussion.
2. Build an if-then stucture for your update calls, that goes like this
(this assumes that your primary key is SERIAL):
IF primarykey_variable = 0 THEN
INSERT INTO table1 (field1, field2, field3)
VALUES (variable1, variable2, variable3);
ELSE
UPDATE table1 SET field1 = variable1,
field2 = variable2,
field3 = variable3
WHERE primarykey = primarykey_variable;
END IF;
-Josh Berkus
--
______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, jdiehl@sandia.gov
Subject: Re: mysql's "replace into..."
In-Reply-To: <3A9D57F4.E85E3E6E@agliodbs.com>
References: <B51F0C636E578A4E832D3958690CD73E0130BE49@es04snlnt> <3A9D57F4.E85E3E6E@agliodbs.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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