Skip site navigation (1) Skip section navigation (2)

Re: date range to set of dates expansion

From: Samuel Gendler <sgendler(at)ideasculptor(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
Subject: Re: date range to set of dates expansion
Date: 2012-01-19 17:17:17
Message-ID: CAEV0TzBOpA+VdkQ-NeW5dhEc5EWOxFASsoogF0FCL1K_P_q_cA@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
On Thu, Jan 19, 2012 at 8:20 AM, Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>wrote:

> On Thursday, January 19, 2012 7:59:27 am Gary Stainburn wrote:
> > The following code works in 8.4 but not 8.3.
> > Anyone know why, or what I need to do to change it?
> >
> > SELECT aid, asid,
> >        date_range (asdate, afdate)::date AS asdate,
> >        acomments
> > FROM availability
> >
> > In 8.4 it returns the expanded dataset as required. In 8.3 I get:
> >
> > ERROR:  set-valued function called in context that cannot accept a set
> > CONTEXT:  PL/pgSQL function "date_range" line 4 at RETURN NEXT
>
> As to why it works in 8.4 vs 8.3
>
> http://www.postgresql.org/docs/8.4/interactive/release-8-4.html
>
> "Support set-returning functions in SELECT result lists even for functions
> that
> return their result via a tuplestore (Tom)
>
> In particular, this means that functions written in PL/pgSQL and other PL
> languages can now be called this way.'
>
> In 8.3- I believe you could only call it as
>
> SELECT * from date_range (asdate, afdate)::date AS asdate;
>

I don't think you can have that cast there when it is in the from-clause.
 You can refer to its values in the select clause explicitly if you alias
the the results:

select r.range_date::date from date_range(asfdate, afdate) as
r(range_date); Presumably, you can fashion something that satisfies your
needs by putting something like this in a subquery which refers to the
start and end date in each row of the outer query.  I'm in a rush, so no
time to figure out a working demo for you.

--sam

In response to

Responses

pgsql-sql by date

Next:From: Gary StainburnDate: 2012-01-19 17:27:27
Subject: Re: date range to set of dates expansion
Previous:From: Steve CrawfordDate: 2012-01-19 16:50:53
Subject: Re: date range to set of dates expansion

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group