Re: Incrementar campo de tipo date.

From: Carlos Agustín López Avila <cagustinla(at)gmail(dot)com>
To: PostgreSQL <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Incrementar campo de tipo date.
Date: 2009-11-19 04:35:02
Message-ID: 4B04CAF6.4060507@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

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: Re: [pgsql-es-ayuda] Incrementar campo de tipo date.
> To: "PostgreSQL" <pgsql-es-ayuda(at)postgresql(dot)org>
> Date: Thursday, November 19, 2009, 4:01 AM
>
> Lennin Caro escribió:
> > --- On *Thu, 11/19/09, Carlos Agustín López Avila
> > /<cagustinla(at)gmail(dot)com </mc/compose?to=cagustinla(at)gmail(dot)com>>/*
> wrote:
> >
> >
> > From: Carlos Agustín López Avila <cagustinla(at)gmail(dot)com
> </mc/compose?to=cagustinla(at)gmail(dot)com>>
> > Subject: Re: [pgsql-es-ayuda] Incrementar campo de tipo date.
> > To: "PostgreSQL" <pgsql-es-ayuda(at)postgresql(dot)org
> </mc/compose?to=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
> </mc/compose?to=cagustinla(at)gmail(dot)com>
> </mc/compose?to=cagustinla(at)gmail(dot)com
> </mc/compose?to=cagustinla(at)gmail(dot)com>>>/*
> > wrote:
> > >
> > >
> > > From: Carlos Agustín López Avila <cagustinla(at)gmail(dot)com
> </mc/compose?to=cagustinla(at)gmail(dot)com>
> > </mc/compose?to=cagustinla(at)gmail(dot)com
> </mc/compose?to=cagustinla(at)gmail(dot)com>>>
> > > Subject: [pgsql-es-ayuda] Incrementar campo de tipo date.
> > > To: "PostgreSQL" <pgsql-es-ayuda(at)postgresql(dot)org
> </mc/compose?to=pgsql-es-ayuda(at)postgresql(dot)org>
> > </mc/compose?to=pgsql-es-ayuda(at)postgresql(dot)org
> </mc/compose?to=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
> >
> >
> Muchas, pero muchas gracias.
>
> a la orden
> comenta si e funciono
>
>
Siguiendo a Lennin así me quedo:
create table pato (
fecha date,
anios int2,
meses int2,
dias int2
);
insert into pato (date('2009-12-31'), 1, 2,3);
select * from pato
where (fecha + (anios || ' years')::interval + (meses || '
month')::interval + (dias || ' days')::interval) < current_date
from tabla;

Nuevamente gracias.

Attachment Content-Type Size
cagustinla.vcf text/x-vcard 201 bytes

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message suso 2009-11-19 08:56:36 Re: encriptar registros o tablas
Previous Message Lennin Caro 2009-11-19 04:06:59 Re: Incrementar campo de tipo date.