Обсуждение: CALCULAR EDAD!

Поиск
Список
Период
Сортировка

CALCULAR EDAD!

От
"juan jose dominguez"
Дата:
Buenas, queria saber como sacar la edad de alguien. Me da el siguiente error con el siguiente codigo :


-- Function: funcion_saca_edad()
DROP TRIGGER trigger_saca_edad ON fechas;
DROP FUNCTION funcion_saca_edad ();
CREATE OR REPLACE FUNCTION funcion_saca_edad() RETURNS OPAQUE AS'
DECLARE
edad timestamp;
BEGIN
edad := age(CURRENT_DATE,NEW.fecha);
RAISE NOTICE ''edad : %'',edad;
RAISE NOTICE ''32131231'';
RETURN NEW;
END;
'LANGUAGE 'plpgsql';
CREATE TRIGGER trigger_saca_edad BEFORE INSERT OR UPDATE ON fechas
FOR EACH ROW EXECUTE PROCEDURE funcion_saca_edad ();


INSERT INTO fechas VALUES ('10/07/83');


ERROR:  invalid input syntax for type timestamp: "22 years 6 mons 20 days"
CONTEXT:  PL/pgSQL function "funcion_saca_edad" line 6 at assignment


Tu horóscopo diario, semanal y gratuito.  Cartas, tarot y predicciones en MSN Horóscopo

Re: CALCULAR EDAD!

От
Andreas Kretschmer
Дата:
juan jose dominguez <preguntas_sql@hotmail.com> schrieb:

> Buenas, queria saber como sacar la edad de alguien. Me da el siguiente error
> con el siguiente codigo :
>      **** ---- FFuunnccttiioonn:: ffuunncciioonn__ssaaccaa__eeddaadd(()) ****
>      **** DDRROOPP TTRRIIGGGGEERR ttrriiggggeerr__ssaaccaa__eeddaadd OONN
ffeecchhaass;;**** 
>      **** DDRROOPP FFUUNNCCTTIIOONN ffuunncciioonn__ssaaccaa__eeddaadd (());;
****
>      **** CCRREEAATTEE OORR RREEPPLLAACCEE FFUUNNCCTTIIOONN
ffuunncciioonn__ssaaccaa__eeddaadd(())RREETTUURRNNSS OOPPAAQQUUEE AASS'' 
>      ****

Please, NO HTML!

> INSERT INTO fechas VALUES ('10/07/83');
> ERROR:  invalid input syntax for type timestamp: "22 years 6 mons 20 days"
> CONTEXT:  PL/pgSQL function "funcion_saca_edad" line 6 at assignment

The age() function returns not a timestamp, it returns a interval.


Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."    (unknow)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°