Cara, era isso mesmo que eu precisava !!
Obrigado !

----- Original Message ----- 
From: "Osvaldo Kussama" <[EMAIL PROTECTED]>
To: "Comunidade PostgreSQL Brasileira" <pgbr-geral@listas.postgresql.org.br>
Sent: Wednesday, June 11, 2008 10:54 AM
Subject: Re: [pgbr-geral] Período


Em 11/06/08, Vinicius Santos - MSI<[EMAIL PROTECTED]> escreveu:
> Acho que me expressei errado....eu não tenho tais dados em nenhuma
> tabela....
> gostaria de fazer um SELECT usando alguma função talvez....para retornar
> todas as datas do período...
>
>
> ----- Original Message -----
> From: "Leandro Augusto Kisielewicz" <[EMAIL PROTECTED]>
> To: "Comunidade PostgreSQL Brasileira" 
> <pgbr-geral@listas.postgresql.org.br>
> Sent: Wednesday, June 11, 2008 10:38 AM
> Subject: Re: [pgbr-geral] Período
>
>
>> select * from tabela where data between 2008-06-01 and 2008-06-05
>>
>> (Conjunto fechado)
>>
>> On Wednesday 11 June 2008 10:36:10 Vinicius Santos - MSI wrote:
>>> Pessoal, existe alguma maneira de retornar todas as datas de um
>>> determinado
>>> período ?
>>>
>>> Por exemplo, select * from "período de 01/06/2008 a 05/06/2008", para
>> retornar o seguinte:
>>> |Data|
>>>
>>> 01/06/2008
>>> 02/06/2008
>>> 03/06/2008
>>> 04/06/2008
>>> 05/06/2008
>>


SELECT (inicio + i)::date   FROM generate_series(0, fim - inicio) i;

Onde início e fim são suas datas. Se desejar uma função tente esta:

CREATE OR REPLACE FUNCTION gen_datas(inicio date, fim date)
RETURNS SETOF date AS $$
  SELECT $1 + i
    FROM generate_series(0, $2 - $1) i;
$$ LANGUAGE SQL IMMUTABLE;

Osvaldo
_______________________________________________
pgbr-geral mailing list
pgbr-geral@listas.postgresql.org.br
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

_______________________________________________
pgbr-geral mailing list
pgbr-geral@listas.postgresql.org.br
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Reply via email to