Re: Postgres for a "data warehouse", 5-10 TB

From: Andy Colson <andy(at)squeakycode(dot)net>
To: Igor Chudov <ichudov(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Postgres for a "data warehouse", 5-10 TB
Date: 2011-09-11 14:23:20
Message-ID: 4E6CC458.4010206@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 every week, 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

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Claudio Freire 2011-09-11 14:27:44 Re: Postgres for a "data warehouse", 5-10 TB
Previous Message Igor Chudov 2011-09-11 14:21:35 Re: Postgres for a "data warehouse", 5-10 TB