pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Diehl, Jeffrey <jdiehl@sandia.gov>
To: sqllist <pgsql-sql@postgresql.org>
Subject: Re: mysql's "replace into..."
Date: Wed, 28 Feb 2001 14:06:12 -0800
Message-ID: <3A9D7654.453E40A9@agliodbs.com> (raw)
References: <B51F0C636E578A4E832D3958690CD73E0130BE4C@es04snlnt>

Jeff,

> Thanx for your help.  I found replace into to be a nice convience since my
> primary keys are often expressions build from several fields which I want to
> keep unique.  Replace into enforces this uniqueness.  I was learning SQL
> when I started this project so I didn't know this was non-standard.  Bummer.

No, what you're describing are called "composite keys".  They are a
standard part of SQL, but most developers end up using numerical
surrogate keys because they are easier to handle.

> But since my primary keys are expressions, I can't use the technique you
> suggested.  I'm thinking of simply trying the insert and checking to see if
> I get an error.  If I get an error, I do an update...  Not sure how well
> this will work, tho.

Better to do it the other way. Search for that key; if it's returned, do
an update; if the results are NULL, do an insert.  If your table has few
fields (<15) you can even do this through a function, passing the field
values as parameters of the function.

					-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



view thread (4+ messages)

Message-ID: <3A9D7654.453E40A9@agliodbs.com>
Permalink:  ../3A9D7654.453E40A9@agliodbs.com/
Also on:    postgresql.org/message-id/3A9D7654.453E40A9@agliodbs.com

 · 

reply

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: <3A9D7654.453E40A9@agliodbs.com>
  References: <B51F0C636E578A4E832D3958690CD73E0130BE4C@es04snlnt> <3A9D7654.453E40A9@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