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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Pregunta sobre trigger


  • From: Aarón Ribas Núñez <ribas_ibiza(at)hotmail(dot)com>
  • To: pgsql-es-ayuda(at)postgresql(dot)org
  • Subject: Pregunta sobre trigger
  • Date: Thu, 31 May 2007 13:19:25 +0200
  • Message-id: <BAY108-F179A2862D2060753F34C27822D0(at)phx(dot)gbl>

Hola, muy buenas. Tengo una duda sobre una práctica que estoy haciendo, es una base de datos sobre Linux, en PostgreSQL, obviamente. Mi duda, o problema es el siguiente: tengo que hacer un trigger sobre una facturación mensual de un usuario. Tengo una tabla factura:

CREATE TABLE Factura(
	nºfactura char(6) PRIMARY KEY,
	NIF char(9),
	importe float DEFAULT 0.0 NOT NULL,
	IVA float DEFAULT 16.0,
	id_correo integer,
       fecha_cobro date NOT NULL,
	constraint factura_usuario FOREIGN KEY (NIF) REFERENCES usuario(NIF),
constraint factura_cuentacorreo FOREIGN KEY (id_correo) REFERENCES Cuentacorreo(id_cuentacorreo)

He hecho el trigger de la siguiente manera:

CREATE OR REPLACE FUNCTION factura_mensual()
RETURNS TRIGGER language 'PLPGSQL' AS'

DECLARE

res float;
lista_fact record;

BEGIN
select importe into lista_fact from factura where factura.fecha_cobro < 2007-05-01 and nif = 765432199;

	res = lista_fact.importe * 1.16;
	RETURN res;
END;';

CREATE TRIGGER factura_mensual AFTER INSERT OR UPDATE ON factura
FOR EACH ROW EXECUTE PROCEDURE factura_mensual();

cuando cargo la base de datos: \i bd.sql , me sale que se crea la funcion y el trigger, sin errores en la compilacióm:

CREATE FUNCTION
CREATE TRIGGER

pero al hacer un insert, es cuando da error, hago lo siguiente:

INSERT INTO factura VALUES ('00600','123456789','200','16.0','3','2007-10-2');

y el error que me sale es:

ERROR:  return type mismatch in function returning tuple at or near "res"
CONTEXT:  compile of PL/pgSQL function "factura_mensual" near line 11

He probado muchas cosas, he mirado por foros y demás, pero no encuentro la solución. Espero me puedan ayudar y disculpen las moletias. Gracias de antemano

Un saludo, Enrique.

_________________________________________________________________
Dale rienda suelta a tu tiempo libre. Mil ideas para exprimir tu ocio con MSN Entretenimiento. http://entretenimiento.msn.es/




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group