0

this is my table

CREATE TABLE pago
(
  codigo serial NOT NULL,
  codigocaja integer NOT NULL,
  codigotarjeta integer,
  codigocheque integer,
  formapago character varying(1) NOT NULL,
  tipocomp character varying(1) NOT NULL,
  importetotal money NOT NULL,
  fecha date NOT NULL,
  codigoalumno integer NOT NULL,
  codigodeposito integer,
  vigencia boolean NOT NULL DEFAULT true,
  descripcion character varying(200),
  CONSTRAINT "PK_CodigoPago" PRIMARY KEY (codigo),
  CONSTRAINT "FK_CodigoAlumno" FOREIGN KEY (codigoalumno)
      REFERENCES alumno (codigoalumno) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "FK_CodigoCaja" FOREIGN KEY (codigocaja)
      REFERENCES caja (codigo) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "FK_CodigoCheque" FOREIGN KEY (codigocheque)
      REFERENCES cheque (codigo) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "FK_CodigoDeposito" FOREIGN KEY (codigodeposito)
      REFERENCES deposito (codigo) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "FK_CodigoTarjeta" FOREIGN KEY (codigotarjeta)
      REFERENCES tarjeta (codigo) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "UN_CodigoPago" UNIQUE (codigo)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE pago
  OWNER TO postgres;

and this is my function for adding a new row

CREATE OR REPLACE FUNCTION fn_inspagar(vcodcaja integer, vcodtarjeta integer, vcodcheque integer,  vformapago character varying, vtipocomp character varying,vimporte money ,vfecha date, vcodal integer, vcoddeposito integer,vdesc character varying)
  RETURNS void AS
$BODY$
begin

INSERT INTO pago(codigocaja,codigotarjeta,codigocheque,formapago,tipocomp,importetotal,fecha,codigoalumno,codigodeposito,descripcion)
VALUES (vcodcaja,vcodtarjeta,vcodcheque,vformapago,vtipocomp,vimporte,vfecha,vcodal,vcoddeposito,vdesc);

end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;

and when i execute the functions like this

select * from fn_inspagar(1,2,null,'T','B',200,'2013-01-01',196,0,'matricula')

as a result i have the following

ERROR: no existe la función fn_inspagar(integer, integer, integer, unknown, unknown, integer, unknown, integer, integer, unknown)

5
  • 1
    I think you've missed the actual problem off the end of your question...
    – IMSoP
    May 29, 2013 at 22:26
  • Sorry! it is update now!
    – MitoCode
    May 29, 2013 at 22:31
  • fn_inspagar() vs fn_inspago(). (looks like a typo) May 29, 2013 at 22:49
  • 1
    I would stay away from the money datatype. Use decimal instead. That will cause much fewer trouble in the long run.
    – user330315
    May 29, 2013 at 23:32
  • Let me just echo @a_horse_with_no_name; I found the money datatype to be much more trouble than it was worth, especially for a multi-currency application. Decimal with an implied decimal place (4 or 6) worked better. May 30, 2013 at 7:20

1 Answer 1

2

Because the money type is not a 'trivial conversion', you need to cast the 200 value in your example as money when calling the function (otherwise PostgreSQL gives the priority to an integer conversion).

Working example:

select * from fn_inspagar(1,2, null, 'T', 'B',CAST ( 200 as money) , '2013-01-01' ,196,0, 'matricula')

Have a look here to get more informations on how PostgreSQL handles the signature of functions:

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.