From: | Lennin Caro <lennin(dot)caro(at)yahoo(dot)com> |
---|---|
To: | PostgreSQL <pgsql-es-ayuda(at)postgresql(dot)org>, Carlos Agustín López Avila <cagustinla(at)gmail(dot)com> |
Subject: | Re: Incrementar campo de tipo date. |
Date: | 2009-11-19 03:57:28 |
Message-ID: | 154399.41532.qm@web59502.mail.ac4.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
--- On Thu, 11/19/09, Carlos Agustín López Avila <cagustinla(at)gmail(dot)com> wrote:
From: Carlos Agustín López Avila <cagustinla(at)gmail(dot)com>
Subject: Re: [pgsql-es-ayuda] Incrementar campo de tipo date.
To: "PostgreSQL" <pgsql-es-ayuda(at)postgresql(dot)org>
Date: Thursday, November 19, 2009, 3:01 AM
Lennin Caro escribió:
>
> --- On *Thu, 11/19/09, Carlos Agustín López Avila
> /<cagustinla(at)gmail(dot)com>/* wrote:
>
>
> From: Carlos Agustín López Avila <cagustinla(at)gmail(dot)com>
> Subject: [pgsql-es-ayuda] Incrementar campo de tipo date.
> To: "PostgreSQL" <pgsql-es-ayuda(at)postgresql(dot)org>
> Date: Thursday, November 19, 2009, 2:23 AM
>
> Buena noches a todos.
> Necesito incrementar un campo de tipo date con cantidades
> numericas que representan años, meses y dias. ejemplo
> select fecha + 10 años + 2 meses + 4 dias from tabla;
>
> Gracias.
>
> -----Inline Attachment Follows-----
>
> --
> TIP 5: ¿Has leído nuestro extenso FAQ?
> http://www.postgresql.org/docs/faqs.FAQ.html
>
>
> con esto puedes incrementar un mes
>
> select current_date + interval '1 months'
>
> mas referncias
>
> http://www.postgresql.org/docs/8.3/interactive/functions-datetime.html
>
>
Perdón pero creo que expuse mal la pregunta.
Tengo una entidad con esta definición
create table pato (
fecha date,
anios int2,
mese int2,
dias int2
);
y lo que necesito es algo como esto
select fecha + anios + meses + dias;
Muchas gracias por su apoyo.
-----Inline Attachment Follows-----
--
TIP 10: no uses HTML en tu pregunta, seguro que quien responda no podrá leerlo
Esto me funciono
tabla
CREATE TABLE prueba
(
id integer NOT NULL,
fecha date,
anio integer,
mes integer,
dia integer,
CONSTRAINT prueba_pkey PRIMARY KEY (id)
)
funcion
CREATE OR REPLACE FUNCTION dateadd2(integer, integer, integer, inputdate date)
RETURNS date AS
$BODY$
DECLARE
strq varchar;
dateTemp Date;
dprec RECORD;
BEGIN
strq:='select current_date + interval '''|| $1 || ' year'' + interval '''|| $2 || ' month'' + interval '''|| $3 || ' day'' as fecha' ;
FOR dprec IN EXECUTE strq LOOP
dateTemp := dprec.fecha;
END LOOP;
RETURN dateTemp;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
llamada
select dateadd2(anio,mes,dia,fecha) from prueba
From | Date | Subject | |
---|---|---|---|
Next Message | Carlos Agustín López Avila | 2009-11-19 04:01:41 | Re: Incrementar campo de tipo date. |
Previous Message | Jaime Casanova | 2009-11-19 03:15:42 | Re: encriptar registros o tablas |