X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 06FB09FB1BA for ; Tue, 6 Jun 2006 18:04:15 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 56542-06 for ; Tue, 6 Jun 2006 18:04:04 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from newman.kshs.org (site.kshs.org [165.201.138.10]) by postgresql.org (Postfix) with ESMTP id 675269FB1B9 for ; Tue, 6 Jun 2006 18:04:05 -0300 (ADT) Received: from [172.25.9.42] (unknown [172.25.9.42]) by newman.kshs.org (Postfix) with ESMTP id 35A4E10E69B for ; Tue, 6 Jun 2006 15:59:32 -0500 (CDT) Message-ID: <4485EE67.5060005@kshs.org> Date: Tue, 06 Jun 2006 16:06:47 -0500 From: Christine Desmuke Organization: Kansas State Historical Society User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: How to get list of days between two dates? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/73 X-Sequence-Number: 25309 Hello, I'm trying to write a query and cannot figure out how to do it (or whether it can be done in SQL alone). Given a table containing events with their starting and ending days (may be single- or multi-day events), I need a list of the events occurring each day: CREATE TABLE test_events ( event_id serial, event_name text, start_time date, end_time date, CONSTRAINT event_pkey PRIMARY KEY (event_id) ); INSERT INTO test_events (event_name, start_time, end_time) VALUES ('First Event', '05/01/2006', '05/04/2006'); INSERT INTO test_events (event_name, start_time, end_time) VALUES ('Second Event', '05/02/2006', '05/02/2006'); INSERT INTO test_events (event_name, start_time, end_time) VALUES ('Third Event', '05/04/2006', '05/05/2006'); INSERT INTO test_events (event_name, start_time, end_time) VALUES ('Fourth Event', '05/07/2006', '05/07/2006'); The query results should look like: 5/1/2006 First Event 5/2/2006 First Event 5/2/2006 Second Event 5/3/2006 First Event 5/4/2006 First Event 5/4/2006 Third Event 5/5/2006 Third Event 5/7/2006 Fourth Event I've been experimenting with set-returning functions, but I haven't stumbled on the answer. Suggestions? Thanks --christine Christine Desmuke Database Administrator Kansas State Historical Society Topeka, KS cdesmuke@kshs.org