Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 621BC16E34F8 for ; Sat, 17 Dec 2011 14:09:55 -0400 (AST) Received: from mail-iy0-f174.google.com ([209.85.210.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Rbyhj-0000Yw-0b for pgsql-sql@postgresql.org; Sat, 17 Dec 2011 18:09:55 +0000 Received: by iaeh11 with SMTP id h11so6139666iae.19 for ; Sat, 17 Dec 2011 10:09:38 -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=SQbcb7XwB+35WbCfol3vgTFd8D8f43VXuO6IbTtvwVc=; b=O9LoKvU+7k5n9Du0W81Ev95309cavtV2PBLPdzYuV0qAOKa0xpsfz4KaalU9v0avn6 we8umjOChUj1fDdBsSpZXZNIw7FvDhk58ByaQQYvVtKJRUt3wuOekzhCk6VRrz2YmOJO HqPmZwIYuWA+2yXe+wXRU6XGOGedPNs1eRD1g= Received: by 10.50.46.167 with SMTP id w7mr16524927igm.88.1324145378307; Sat, 17 Dec 2011 10:09:38 -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 g34sm46768418ibk.10.2011.12.17.10.09.35 (version=SSLv3 cipher=OTHER); Sat, 17 Dec 2011 10:09:36 -0800 (PST) From: Adrian Klaver To: pgsql-sql@postgresql.org Subject: Re: using a generated series in function Date: Sat, 17 Dec 2011 10:09:31 -0800 User-Agent: KMail/1.13.5 (Linux/2.6.32-36-generic; KDE/4.4.5; i686; ; ) Cc: John Fabiani References: <-6224470694062641569@unknownmsgid> <201112160731.41028.adrian.klaver@gmail.com> <101859121.8q3HjkjhPI@linux-12> In-Reply-To: <101859121.8q3HjkjhPI@linux-12> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201112171009.32373.adrian.klaver@gmail.com> X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201112/69 X-Sequence-Number: 36130 On Saturday, December 17, 2011 8:50:52 am John Fabiani wrote: > 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()? If it makes you happier:) test(5432)aklaver=>SELECT * from now(); now ------------------------------- 2011-12-17 10:00:34.929144-08 (1 row) > > 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. SELECT List "The SELECT list (between the key words SELECT and FROM) specifies expressions that form the output rows of the SELECT statement. The expressions can (and usually do) refer to columns computed in the FROM clause." So items in the SELECT are not required to be derived from as FROM clause > > 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'! It is a Postgres extension to the SQL standard: http://www.postgresql.org/docs/9.0/interactive/sql-select.html#SQL-SELECT-LIST Compatibility " Omitted FROM Clauses PostgreSQL allows one to omit the FROM clause. It has a straightforward use to compute the results of simple expressions: SELECT 2+2; ?column? ---------- 4 Some other SQL databases cannot do this except by introducing a dummy one-row table from which to do the SELECT. Note that if a FROM clause is not specified, the query cannot reference any database tables. For example, the following query is invalid: SELECT distributors.* WHERE distributors.name = 'Westward'; PostgreSQL releases prior to 8.1 would accept queries of this form, and add an implicit entry to the query's FROM clause for each table referenced by the query. This is no longer allowed. " > > As always everyone - thanks for your help! > -- Adrian Klaver adrian.klaver@gmail.com