From: | Josh Berkus <josh(at)agliodbs(dot)com> |
---|---|
To: | "Diehl, Jeffrey" <jdiehl(at)sandia(dot)gov>, sqllist <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: mysql's "replace into..." |
Date: | 2001-02-28 22:06:12 |
Message-ID: | 3A9D7654.453E40A9@agliodbs.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
From | Date | Subject | |
---|---|---|---|
Next Message | Jacek Zagorski | 2001-02-28 23:29:21 | Insert into VIEW ??? |
Previous Message | Diehl, Jeffrey | 2001-02-28 20:40:37 | RE: mysql's "replace into..." |