Re: ayuda TRIGGER

From: Guillermo Villanueva <guillermovil(at)gmail(dot)com>
To: Henrry Joshney Servitá Sánchez <henser05(at)yahoo(dot)com>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: ayuda TRIGGER
Date: 2010-06-10 11:17:37
Message-ID: AANLkTimHtubQNEHdvSOwlig9_qx2RwmHx9RECsvIOw6N@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Henry, no me quedó muy claro en que necesitás ayuda.
De todas maneras, con respecto al diseño, no entiendo el sentido que tengas
el campo stock en otra tabla. Si esa otra tabla tendría por ejemplo un campo
adicional de fecha, y que ahí puedas tener un historial de stock, sería mas
comprensible, pero solo quantity y item_id te dan una relación de uno a uno
que al menos yo no le veo sentido.

Saludos

~~~~~~~~~~~~~~~~
Guillermo Villanueva

2010/6/10 Henrry Joshney Servitá Sánchez <henser05(at)yahoo(dot)com>

> buenas tengo las siguientes tablas.
>
> CREATE TABLE item
> (
> item_id serial NOT NULL,
> description character varying(64) NOT NULL,
> cost_price numeric(7,2),
> sell_price numeric(7,2),
> CONSTRAINT item_pk PRIMARY KEY (item_id)
> )
> WITH (
> OIDS=FALSE
> );
>
> CREATE TABLE stock
> (
> item_id integer NOT NULL,
> quantity integer NOT NULL,
> CONSTRAINT stock_pk PRIMARY KEY (item_id)
> )
> WITH (
> OIDS=FALSE
> );
>
> estoy creando un trigger que me controle al momento de insertar un nuevo
> registro en la tabla item se inserte otro registro en la tabla stock con el
> campo item_id de la tabla iten y el quantity con el valor 0.
>
> esta es la funcion que cree
>
> CREATE OR REPLACE FUNCTION nuevo_producto() RETURNS trigger AS
> $BODY$
> declare
> codigo int;
> BEGIN
> if (TG_OP='INSERT' ) THEN
> IF (NEW.item_id != NEW.item_id) then
>
>
> INSERT INTO item VALUES (item_id,
> description,cost_price,sell_price);
>
> insert into stock values(item.item_id,0);
>
> ELSE
> RAISE NOTICE 'fallo';--, quantity; -- Prints 30
>
> END IF;
> end if;
> RETURN null;
> END;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE;
>
> create trigger insertar_producto
> after insert on item
> for each row
> execute procedure nuevo_producto();
>
>
> espero que haya sido claro y puedan ayudarme muchas gracias.
>
> saludos
>
>
>
> -
> Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda(at)postgresql(dot)org
> )
> Para cambiar tu suscripción:
> http://www.postgresql.org/mailpref/pgsql-es-ayuda
>

In response to

  • ayuda TRIGGER at 2010-06-10 03:59:56 from Henrry Joshney Servitá Sánchez

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Guillermo Villanueva 2010-06-10 12:46:52 Re: ayuda TRIGGER
Previous Message Jaime Casanova 2010-06-10 04:42:56 Re: ayuda sobre SRF