Skip site navigation (1) Skip section navigation (2)

Re: ALIAS para tablas en PostgreSQL

From: Javier Chávez B(dot) <jchavezb(at)gmail(dot)com>
To: "Jaime Casanova" <jcasanov(at)systemguards(dot)com(dot)ec>
Cc: "Diego Ayala" <netdiego81(at)gmail(dot)com>, "Alvaro Herrera" <alvherre(at)alvh(dot)no-ip(dot)org>, "Postgres Ayuda" <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: ALIAS para tablas en PostgreSQL
Date: 2008-11-27 15:43:53
Message-ID: ded64bba0811270743n7a90bc49ye49c5181bc3adbb2@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-es-ayuda
On Thu, Nov 27, 2008 at 3:36 PM, Jaime Casanova
<jcasanov(at)systemguards(dot)com(dot)ec> wrote:
> On Thu, Nov 27, 2008 at 10:27 AM, Javier Chávez B. <jchavezb(at)gmail(dot)com> wrote:
>>>
>>> Algo asi:
>>> create view bar as select * from foo;
>>>
>>> --replace * with the actual names of columns for every column you want to affect
>>> create rule r_insert_bar as on insert to bar do instead insert into
>>> foo values (new.*);
>>> create rule r_update_bar as on update to bar do instead update foo set
>>> * = new.* where pk =old.pk;
>>> create rule r_delete_bar as on delete to bar do instead delete from
>>> where pk =old.pk;
>>
>> O sea de esta manera estoy actualizando una vista pero le indico que
>> actualice los campos fisicos que lo componen verdad??? su manera de
>> trabajo es como una especie de trigger???
>>
>
> no. una vista es un select con un nombre. no tiene campos fisicos...
> mas bien el DO INSTEAD le dice que en lugar de ejecutar la sentencia
> que tu le pasaste (ej: INSERT INTO mivista) ejecute la sentencia que
> yo le digo... es mas un re-escritor de consultas (una forma de macro
> si se quiere)

Dejame entender bien la idea ....

Alvaro dijo lo siguiente :

create view bar as select * from foo;

Tu posteaste :

>>> --replace * with the actual names of columns for every column you want to affect
>>> create rule r_insert_bar as on insert to bar do instead insert into
>>> foo values (new.*);
>>> create rule r_update_bar as on update to bar do instead update foo set
>>> * = new.* where pk =old.pk;
>>> create rule r_delete_bar as on delete to bar do instead delete from
>>> where pk =old.pk;
 Lo que daria como resultado algo asi :

create view bar as
  select create rule r_insert_bar as   on insert   to bar do instead
insert into foo values (new.*);
            create rule r_update_bar as on update to bar do instead
update foo set  * = new.* where pk =old.pk;
            create rule r_delete_bar as on delete to bar do instead
delete from where pk =old.pk;    from foo;

La sintaxis seria esa???  ( en terminos generales por supuesto)  o
no???  y lo que haria seria para cada una de las sentencias
Insert/Delete / Update , realizar una accion en la tabla fisica... va
por ahi ???

Slds
J

-- 
Cumprimentos
jchavez
linux User #397972 on http://counter.li.org/

In response to

Responses

pgsql-es-ayuda by date

Next:From: Jaime CasanovaDate: 2008-11-27 16:05:01
Subject: Re: ALIAS para tablas en PostgreSQL
Previous:From: Jaime CasanovaDate: 2008-11-27 15:36:01
Subject: Re: ALIAS para tablas en PostgreSQL

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group