insert into view !!

Started by Jonathan davisalmost 27 years ago3 messagesgeneral
Jump to latest
#1Jonathan davis
haj@idianet.net

it is possible to insert into a view ?

thanks

#2Howie
caffeine@toodarkpark.org
In reply to: Jonathan davis (#1)
Re: [GENERAL] insert into view !!

On Wed, 23 Jun 1999, abdelkrim wrote:

it is possible to insert into a view ?

if its a single-table view, yes -- you'd want to create a DO INSTEAD rule.
consult the manual/html pages to get the proper syntax for CREATE RULE.

if its a multitable view, maybe... i dont think this can be done with a
single rule, however. you'll most likely need to implement a pl/pgsql or
pl/tcl function.

---
Howie <caffeine@toodarkpark.org> URL: http://www.toodarkpark.org
"The distance between insanity and genius is measured only by success."

#3José Soares
jose@sferacarta.com
In reply to: Jonathan davis (#1)
Re: [GENERAL] insert into view !!

Try this script:

create table emp (
empno int,
ename char(10),
jobchar(12),
hiredate date,
saldecimal(10,2),
commint,
deptno int,
nivel int,
mgrint
);

create view vista
as select empno, ename, job
from emp
where job='SALESMAN';

create function view_upd() returns opaque as '
begin
if tg_op = ''INSERT'' then
if new.job = ''SALESMAN'' then
INSERT INTO emp VALUES (new.empno,new.ename,new.job);
return new;
else
raise notice ''impossible to add records where JOB is
not "SALES
return null;
end if;
end if;
end;
' language 'plpgsql';

create trigger t_add before insert
on vista for each row execute procedure view_upd();

abdelkrim ha scritto:

it is possible to insert into a view ?

thanks

--
______________________________________________________________
PostgreSQL 6.5.0 on i586-pc-linux-gnu, compiled by gcc 2.7.2.3
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jose'