pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John Fabiani <johnf@jfcomputer.com>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: using a generated series in function
Date: Fri, 16 Dec 2011 02:46:18 -0800
Message-ID: <1479832.Z2paPkhlAQ@linux-12> (raw)
In-Reply-To: <-6224470694062641569@unknownmsgid>
References: <-6224470694062641569@unknownmsgid>

Actually what would the "from" be - this could be a newbie issue here?  
Neither statement requires a "from" because neither of the statements uses a 
table - I think!  I'll try to add one but the first part is a function like a 
any other function.  What is the "from" when you do:
"select now()"  - really I don't know!

The second part is tricky because I don't really understand it.  Howerver, I 
have used it several times (got it off the web somewhere) but only in a "for 
loop".  If I just run it by it's self it generates a table of dates.  
Therefore, I have always thought of it as a function.  Again, like "select 
now()"

So I know this must sound like I'm sort of idiot - just never considered the 
second half (the part that provides the dates) anything other than a postgres 
function.

Johnf
 

On Friday, December 16, 2011 01:30:53 AM Misa Simic wrote:
> It is not totally clear to me what are u trying to do... But in second
> query it seems there is missing "from"
> 
> It is as
> 
> SELECT week-date::date AS week-date WHERE week-date in (subquery which
> have from)
> 
> So week-date column in main query does not exist..
> 
> Sent from my Windows Phone From: John Fabiani
> Sent: 16 December 2011 05:16
> To: pgsql-sql@postgresql.org
> Subject: [SQL] using a generated series in function
> Hi,
> 
> I am attempting (without success) use the generated series of dates that
> come from:
> select (cast(date_trunc('week', '2011-11-20'::date ) as date) + (i+6)) as
> week_date from generate_series(0,84,7) i
> 
> in a function.
> select function_name(integer, date);  -- function returns a numeric
> 
> This does NOT work:
> select (function_name(303, week_date::date)) as week_date where week_date in
> (select (cast(date_trunc('week', '2011-11-20'::date ) as date) + (i+6)) as
> week_date from generate_series(0,84,7) i )
> 
> The error is:
> ERROR:  column "week_date" does not exist
> LINE 1: select (xchromasun._chromasun_getqtyordered(303, week_date::...
> 
> I hope I can do this?  What am I doing wrong?
> Johnf



view thread (12+ messages)  latest in thread

Message-ID: <1479832.Z2paPkhlAQ@linux-12>
Permalink:  ../1479832.Z2paPkhlAQ@linux-12/
Also on:    postgresql.org/message-id/1479832.Z2paPkhlAQ@linux-12

 · 

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: johnf@jfcomputer.com
  Subject: Re: using a generated series in function
  In-Reply-To: <1479832.Z2paPkhlAQ@linux-12>

* 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