update or insert into table from a view - Mailing list pgsql-novice

From Phillip Nelson
Subject update or insert into table from a view
Date
Msg-id 46662FC7.1090704@ints.com
Whole thread Raw
List pgsql-novice
Any help would be greatly appreciated. I am basically attempting to
merge a view into a table. I have been successful at inserting all rows
from the view that do not exist in the table. However, I cannot figure
out how to update the existing rows in the table with those from the
view by primary key. Currently I am doing the following:

insert into statistic_descriptions_data
select seq, "desc", (CASE WHEN epr_flag='Y' THEN TRUE ELSE FALSE END),
(CASE WHEN csr_flag='Y' THEN TRUE ELSE FALSE END), (CASE WHEN
sr_flag='Y' THEN TRUE ELSE FALSE END), (CASE WHEN oil_flag='Y' THEN TRUE
ELSE FALSE END), (CASE WHEN jli_flag='Y' THEN TRUE ELSE FALSE END),
(CASE WHEN msr_flag='Y' THEN TRUE ELSE FALSE END) from ivfs where seq not in
                 (select "sequence" from statistic_descriptions_data);

The table columns are setup as bool where the view is setup with bpchar
for all the flag fields. Thus the case statements to get around cast
problems. Do I need to create a function(), trigger, or something else
to accomplish this. Basically if seq from the view = "sequence" in the
table I need to update that row instead of inserting.
Thanks in advance.

pgsql-novice by date:

Previous
From: "Andrej Ricnik-Bay"
Date:
Subject: Re: Installation of postgresql database as root
Next
From: "Ali, Luqman"
Date:
Subject: Re: Installation of postgresql database as root