Re: using a generated series in function

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: John Fabiani <johnf(at)jfcomputer(dot)com>
Subject: Re: using a generated series in function
Date: 2011-12-17 18:09:31
Message-ID: 201112171009.32373.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message David Johnston 2011-12-17 18:10:40 Re: using a generated series in function
Previous Message John Fabiani 2011-12-17 16:50:52 Re: using a generated series in function