Re: Postgres for a "data warehouse", 5-10 TB - Mailing list pgsql-performance

From Andy Colson
Subject Re: Postgres for a "data warehouse", 5-10 TB
Date
Msg-id 4E6CC458.4010206@squeakycode.net
Whole thread Raw
In response to Re: Postgres for a "data warehouse", 5-10 TB  (Igor Chudov <ichudov@gmail.com>)
Responses Re: Postgres for a "data warehouse", 5-10 TB
List pgsql-performance
On 09/11/2011 08:59 AM, Igor Chudov wrote:
>
>
> I do not plan to do a lot of random writing. My current design is that my perl scripts write to a temporary table
everyweek, and then I do INSERT..ON DUPLICATE KEY UPDATE. 
>
> By the way, does that INSERT UPDATE functionality or something like this exist in Postgres?
>
> i

You have two options:

1) write a function like:
create function doinsert(_id integer, _value text) returns void as $$
begin
   update thetable set value = _value where id = _id;
   if not found then
      insert into thetable(id, value) values (_id, _value);
    end if
end;
$$ language plpgsql;

2) use two sql statements:
-- update the existing
update realTable set value = (select value from tmp where tmp.id = realTable.id)
where exists (select value from tmp where tmp.id = realTable.id);

-- insert the missing
insert into realTable(id, value)
select id, value from tmp where not exists(select 1 from realTable where tmp.id = realTable.id);


-Andy

pgsql-performance by date:

Previous
From: Igor Chudov
Date:
Subject: Re: Postgres for a "data warehouse", 5-10 TB
Next
From: Claudio Freire
Date:
Subject: Re: Postgres for a "data warehouse", 5-10 TB