pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Samuel Gendler <sgendler@ideasculptor.com>
To: Adrian Klaver <adrian.klaver@gmail.com>
Cc: pgsql-sql@postgresql.org, Gary Stainburn <gary.stainburn@ringways.co.uk>
Subject: Re: date range to set of dates expansion
Date: Thu, 19 Jan 2012 09:17:17 -0800
Message-ID: <CAEV0TzBOpA+VdkQ-NeW5dhEc5EWOxFASsoogF0FCL1K_P_q_cA@mail.gmail.com> (raw)
In-Reply-To: <201201190820.06564.adrian.klaver@gmail.com>
References: <201201190713.34333.gary.stainburn@ringways.co.uk>
	<201201191516.16802.gary.stainburn@ringways.co.uk>
	<201201191559.27698.gary.stainburn@ringways.co.uk>
	<201201190820.06564.adrian.klaver@gmail.com>

On Thu, Jan 19, 2012 at 8:20 AM, Adrian Klaver <adrian.klaver@gmail.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

view thread (10+ messages)  latest in thread

Message-ID: <CAEV0TzBOpA+VdkQ-NeW5dhEc5EWOxFASsoogF0FCL1K_P_q_cA@mail.gmail.com>
Permalink:  ../CAEV0TzBOpA+VdkQ-NeW5dhEc5EWOxFASsoogF0FCL1K_P_q_cA@mail.gmail.com/
Also on:    postgresql.org/message-id/CAEV0TzBOpA+VdkQ-NeW5dhEc5EWOxFASsoogF0FCL1K_P_q_cA@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sgendler@ideasculptor.com, adrian.klaver@gmail.com, gary.stainburn@ringways.co.uk
  Subject: Re: date range to set of dates expansion
  In-Reply-To: <CAEV0TzBOpA+VdkQ-NeW5dhEc5EWOxFASsoogF0FCL1K_P_q_cA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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