Re: Pregunta sobre TIMESTAMP y BETWEEN

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Manuel Diego <manuel(at)radiohead(dot)cl>
Cc: Postgres Lista <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Pregunta sobre TIMESTAMP y BETWEEN
Date: 2010-10-31 00:33:05
Message-ID: 1288485003-sup-18@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Excerpts from Manuel Diego's message of vie oct 29 11:57:20 -0300 2010:
> Buenas,
> ¿Alguien sabe como funciona el BETWEEN respecto a las columnas
> TIMESTAMP? Explico mi inquietud:
>
> Si hago:
>
> SELECT * FROM table WHERE columna_timestamp BETWEEN '2010-01-01' AND
> '2010-01-02';
>
> Me trae todas las filas del 2010-01-01 pero no las del 02.

Es natural. Puedes ver exactamente qué está haciendo creando una vista
y mirando cómo imprime la definición. Observa que las fechas se convierten
a timestamp, poniendo las horas en 00:00:00.

alvherre=# create table foo (a timestamp);
CREATE TABLE
alvherre=# create view bar as select * from foo where a between '2010-01-01' and '2010-01-02';
CREATE VIEW
alvherre=# \d+ bar
Vista «alvherre.bar»
Columna │ Tipo │ Modificadores │ Almacenamiento │ Descripción
─────────┼─────────────────────────────┼───────────────┼────────────────┼─────────────
a │ timestamp without time zone │ │ plain │
Definición de vista:
SELECT foo.a
FROM foo
WHERE foo.a >= '2010-01-01 00:00:00'::timestamp without time zone AND foo.a <= '2010-01-02 00:00:00'::timestamp without time zone;

--
Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Horacio Miranda 2010-10-31 00:34:25 Re: duda con table spaces
Previous Message Horacio Miranda 2010-10-31 00:25:09 Re: Pregunta sobre TIMESTAMP y BETWEEN