Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id A8CBA2BF84 for ; Fri, 16 Dec 2011 11:32:04 -0400 (AST) Received: from mail-iy0-f174.google.com ([209.85.210.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RbZlP-0003uV-NY for pgsql-sql@postgresql.org; Fri, 16 Dec 2011 15:32:04 +0000 Received: by iaeh11 with SMTP id h11so4500059iae.19 for ; Fri, 16 Dec 2011 07:31:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; bh=bJVL4Ga01epL+joQQW+Lml9pudq595oCRwj6Bhxxcu0=; b=e1Lc427yGZHCz+m8KublXA3/JSaYwT11ni6dgx3jvLK7P11Ils9mY+Qt24qtFBG2Ap ZKxqJbBiPI0r+0te1yI4Bs7vX9NDhkYVyrHYQpk562ttP1JjfufIfAuvose3zFUODHug YpSL/rbPgThLHNkBSCUfmuic4QGKnUD1Im3x4= Received: by 10.50.104.137 with SMTP id ge9mr9206953igb.38.1324049506729; Fri, 16 Dec 2011 07:31:46 -0800 (PST) Received: from tucker.localnet (c-24-17-164-54.hsd1.wa.comcast.net. [24.17.164.54]) by mx.google.com with ESMTPS id gf6sm3126564igb.1.2011.12.16.07.31.43 (version=SSLv3 cipher=OTHER); Fri, 16 Dec 2011 07:31:44 -0800 (PST) From: Adrian Klaver To: pgsql-sql@postgresql.org Subject: Re: using a generated series in function Date: Fri, 16 Dec 2011 07:31:40 -0800 User-Agent: KMail/1.13.5 (Linux/2.6.32-36-generic; KDE/4.4.5; i686; ; ) Cc: John Fabiani References: <-6224470694062641569@unknownmsgid> <1479832.Z2paPkhlAQ@linux-12> <1424284.aaP0Qsvkam@linux-12> In-Reply-To: <1424284.aaP0Qsvkam@linux-12> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <201112160731.41028.adrian.klaver@gmail.com> X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201112/62 X-Sequence-Number: 36123 On Friday, December 16, 2011 3:56:48 am John Fabiani wrote: > I have solved my problem. But this still does not explain the idea of > "from"???? =46rom original query: =2E.(function_name(303, week_date::date)) as week_date where week_date.. Reason why that did not work: http://www.postgresql.org/docs/9.0/interactive/sql-select.html SELECT List "... An output column's name can be used to refer to the column's value in ORDER= BY=20 and GROUP BY clauses, but not in the WHERE or HAVING clauses; there you mus= t=20 write out the expression instead. =2E.. " Why the below does work: SELECT List "The SELECT list (between the key words SELECT and FROM) specifies expressi= ons=20 that form the output rows of the SELECT statement. The expressions can (and= =20 usually do) refer to columns computed in the FROM clause" =46ROM Clause "select A sub-SELECT can appear in the FROM clause. This acts as though its out= put=20 were created as a temporary table for the duration of this single SELECT=20 command. Note that the sub-SELECT must be surrounded by parentheses, and an= =20 alias must be provided for it. A VALUES command can also be used here. " >=20 > select foo.week_date, xchromasun._chromasun_getqtyordered(303, > foo.week_date) as week_qty from > (select ((date_trunc('week', '2011-11-20'::date )::date) + (i+6)) as > week_date from generate_series(0,84,7) > i ) as foo >=20 > The above works! >=20 > Johnf >=20 =2D-=20 Adrian Klaver adrian.klaver@gmail.com