Re: most idiomatic way to "update or insert"?

From: Richard Huxton <dev(at)archonet(dot)com>
To: Ron St-Pierre <rstpierre(at)syscor(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: most idiomatic way to "update or insert"?
Date: 2004-08-05 17:37:58
Message-ID: 41127076.3030505@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ron St-Pierre wrote:
> Richard Huxton wrote:
>
>>
>> An "update or insert" would be useful sometimes, but it's not always
>> necessary. Indeed, if I find I don't know whether I'm adding or
>> updating something I take a long hard look at my design - it ususally
>> means I've not thought clearly about something.
>
>> Can you give an actual example of where you need this?
>
> How about stocks for a simple example? Let's say you have a simple table
> with the stock symbol, stock exchange, high, low, open, close and
> volume. Every day you update the data for each stock. But there are
> always new stocks listed on an exchange, so when a new stock shows up
> you have to do an insert instead of an update.

If it is just a simple table then delete all of them and insert from
scratch. If you wanted to track changes over time (perhaps more likely),
you'd have a separate table with the company name/address etc and a log
table. At which point you'll want to know if it's a new company or not...

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron St-Pierre 2004-08-05 18:03:04 Re: most idiomatic way to "update or insert"?
Previous Message Pierre-Frédéric Caillaud 2004-08-05 17:12:03 Re: case insensitive sorting & searching in oracle 10g