From is not required if you use literals or function results (with literal input parameters). If you reference
somethingthat is not one of these it has to come from somewhere and that location is the from/join part of the query.
In your query foo.work_date is not a literal or function and so must be sourced from somewhere. 2011-11-20 is a
literalbeing fed into a function and so does not require a From clause in order to be evaluated.
David J.
On Dec 17, 2011, at 11:50, John Fabiani <johnf@jfcomputer.com> 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()?
>
> 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!
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql