Re: using a generated series in function

From: David Johnston <polobo(at)yahoo(dot)com>
To: John Fabiani <johnf(at)jfcomputer(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: using a generated series in function
Date: 2011-12-17 18:10:40
Message-ID: 441A31E6-ECB7-4A3B-91E6-5D2F32830BFC@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

From is not required if you use literals or function results (with literal input parameters). If you reference something that 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 literal being 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(at)jfcomputer(dot)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(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bèrto ëd Sèra 2011-12-17 21:36:00 Re: Column "..." does not exist (view + union)
Previous Message Adrian Klaver 2011-12-17 18:09:31 Re: using a generated series in function