F_TABLE_NUMBER_RANGE equivalent in Postgresql

From: Yuan HOng <hongyuan1306(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: F_TABLE_NUMBER_RANGE equivalent in Postgresql
Date: 2011-08-16 04:53:00
Message-ID: CANvi9-2uJUWGc8_VJMPq1NGnxVt=KjQihKvorjyLc3WL2MG4DA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

With MS-SQL sever, there is a built-in utility function
dbo.F_TABLE_NUMBER_RANGE which generates a list of number between the
given range. For example:

select dbo.F_TABLE_NUMBER_RANGE(1, 5) will return:

number
-----------
1
2
3
4
5

This is extremely convenient for generating consecutive dates. For
example, I want to find out the daily sales information and if on some
day there is no sales, the query should return 0 instead of a missing
date.

In this case it is necessary to first create a list of consecutive
dates and then left join to some fact table.

With the range function I can simply write something like

select start_date + interval number
from dbo.F_TABLE_NUMBER_RANGE(1, number_of_days)

How does one accomplish such task with Postgresql?

--
Hong Yuan

大管家网上建材超市
装修装潢建材一站式购物
http://www.homemaster.cn

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message msi77 2011-08-16 05:19:00 Re: F_TABLE_NUMBER_RANGE equivalent in Postgresql
Previous Message David Harel 2011-08-15 18:53:26 Re: pgadmin debugger