pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@gmail.com>
To: pgsql-sql@postgresql.org
Cc: John Fabiani <johnf@jfcomputer.com>
Subject: Re: using a generated series in function
Date: Sat, 17 Dec 2011 10:09:31 -0800
Message-ID: <201112171009.32373.adrian.klaver@gmail.com> (raw)
In-Reply-To: <101859121.8q3HjkjhPI@linux-12>
References: <-6224470694062641569@unknownmsgid>
	<201112160731.41028.adrian.klaver@gmail.com>
	<101859121.8q3HjkjhPI@linux-12>

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



view thread (12+ messages)  latest in thread

Message-ID: <201112171009.32373.adrian.klaver@gmail.com>
Permalink:  ../201112171009.32373.adrian.klaver@gmail.com/
Also on:    postgresql.org/message-id/201112171009.32373.adrian.klaver@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: adrian.klaver@gmail.com, johnf@jfcomputer.com
  Subject: Re: using a generated series in function
  In-Reply-To: <201112171009.32373.adrian.klaver@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