Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 787D516E34F8 for ; Sat, 17 Dec 2011 12:51:11 -0400 (AST) Received: from [76.14.161.106] (helo=newserver.jfcomputer.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RbxTa-0007s1-J1 for pgsql-sql@postgresql.org; Sat, 17 Dec 2011 16:51:11 +0000 Received: from localhost (unknown [127.0.0.1]) by newserver.jfcomputer.com (Postfix) with ESMTP id 4F19910C29 for ; Sat, 17 Dec 2011 16:50:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at site Received: from newserver.jfcomputer.com ([127.0.0.1]) by localhost (linux-jfp8.site [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id agJa6B2Vysg4 for ; Sat, 17 Dec 2011 08:50:56 -0800 (PST) Received: from linux-12.localnet (unknown [192.168.1.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: johnf@jfcomputer.com) by newserver.jfcomputer.com (Postfix) with ESMTPSA id 9419BE87 for ; Sat, 17 Dec 2011 08:50:56 -0800 (PST) From: John Fabiani To: pgsql-sql@postgresql.org Subject: Re: using a generated series in function Date: Sat, 17 Dec 2011 08:50:52 -0800 Message-ID: <101859121.8q3HjkjhPI@linux-12> User-Agent: KMail/4.7.2 (Linux/3.1.0-1.2-desktop; KDE/4.7.2; x86_64; ; ) In-Reply-To: <201112160731.41028.adrian.klaver@gmail.com> References: <-6224470694062641569@unknownmsgid> <1424284.aaP0Qsvkam@linux-12> <201112160731.41028.adrian.klaver@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Host-Lookup-Failed: Reverse DNS lookup failed for 76.14.161.106 (failed) X-Pg-Spam-Score: 0.3 (/) X-Archive-Number: 201112/68 X-Sequence-Number: 36129 As always I respect your insights - Adrian. I do understand what I did wrong in my first attempt at getting my statement to work. But it is either over my head or there is something missing. Where is the "from" in select now()? I have been using similar SQL statements for years. I never questioned why there was not a 'from' until this list noted that I was missing a 'From'. I then went to the postgres site to read. That's how I determined what I had done incorrectly. I hope this is not one of those things like javascript where all white space is ignored unless it's not! I hate that language! It appears that everything needs a 'From' in SQL (reading the doc's) and the above statement is missing a 'From'! As always everyone - thanks for your help! Johnf On Friday, December 16, 2011 07:31:40 AM Adrian Klaver wrote: > FROM Clause > "select > > A sub-SELECT can appear in the FROM clause. This acts as though its > output were created as a temporary table for the duration of this single > SELECT command. Note that the sub-SELECT must be surrounded by parentheses, > and an alias must be provided for it. A VALUES command can also be used > here. " > > > > > > > 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 > > > > > > The above works!