pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
DATE SQL
3+ messages / 3 participants
[nested] [flat]

* DATE SQL
@ 2006-03-06 10:39 wanpeng <wanp2005@gmail.com>
  2006-03-06 17:04 ` Re: DATE SQL Mark Lewis <mark.lewis@mir3.com>
  2006-03-07 16:35 ` Re: DATE SQL David Fetter <david@fetter.org>
  0 siblings, 2 replies; 3+ messages in thread

From: wanpeng @ 2006-03-06 10:39 UTC (permalink / raw)
  To: pgsql-jdbc

I want a result like

'2006-03-01'
'2006-03-02'
'2006-03-03' 
'2006-03-04' 


FROM table xxx

……| start_date   |   end_date   |……
    | '2006-03-01' |  '2006-03-04'|

how can I write the sql

thanks

-----------------------------------------------
                         wanp2005@gmail.com          

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: DATE SQL
  2006-03-06 10:39 DATE SQL wanpeng <wanp2005@gmail.com>
@ 2006-03-06 17:04 ` Mark Lewis <mark.lewis@mir3.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Mark Lewis @ 2006-03-06 17:04 UTC (permalink / raw)
  To: wanpeng <wanp2005@gmail.com>; +Cc: pgsql-jdbc

Well, in pure SQL I don't think you could do it without resorting to
ugly tricks like defining an all_days table that had one row per day in
your range, then doing something like, "select from all_days a join xxx
x where a.day >= x.start_date and a.day <= x.end_date"

So . . . don't do that.  What you want isn't really a pure relational
operation, so SQL isn't the right language for it.  Either do it in your
application code, or write a server-side function.

In either case, this is more of a pgsql-general question, since it's not
specific to JDBC at all.

-- Mark Lewis


On Mon, 2006-03-06 at 18:39 +0800, wanpeng wrote:
> I want a result like
> 
> '2006-03-01'
> '2006-03-02'
> '2006-03-03' 
> '2006-03-04' 
> 
> 
> FROM table xxx
> 
> ……| start_date   |   end_date   |……
>     | '2006-03-01' |  '2006-03-04'|
> 
> how can I write the sql
> 
> thanks
> 
> -----------------------------------------------
>                          wanp2005@gmail.com          
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: DATE SQL
  2006-03-06 10:39 DATE SQL wanpeng <wanp2005@gmail.com>
@ 2006-03-07 16:35 ` David Fetter <david@fetter.org>
  1 sibling, 0 replies; 3+ messages in thread

From: David Fetter @ 2006-03-07 16:35 UTC (permalink / raw)
  To: wanpeng <wanp2005@gmail.com>; +Cc: pgsql-jdbc

On Mon, Mar 06, 2006 at 06:39:09PM +0800, wanpeng wrote:
> I want a result like
> 
> '2006-03-01'
> '2006-03-02'
> '2006-03-03' 
> '2006-03-04' 
> 
> 
> FROM table xxx
> 
> ¡­¡­| start_date   |   end_date   |¡­¡­
>     | '2006-03-01' |  '2006-03-04'|
> 
> how can I write the sql

No problem if you're willing to use one of PostgreSQL's built-in
set-returning functions in your target list.

SELECT (
    start_date +
    generate_series(0,end_date-start_date) * interval '1 day'
    )::date AS "range"
FROM your_table;

Cheers,
D
-- 
David Fetter david@fetter.org http://fetter.org/
phone: +1 415 235 3778

Remember to vote!



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2006-03-07 16:35 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-03-06 10:39 DATE SQL wanpeng <wanp2005@gmail.com>
2006-03-06 17:04 ` Mark Lewis <mark.lewis@mir3.com>
2006-03-07 16:35 ` David Fetter <david@fetter.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox