Re: [SQL] using a generated series in function

2011-12-17 Thread Bèrto ëd Sèra
Hi >From is not required if you use literals or function results (with literal > input parameters). If you came from Oracle you could simply think that the "FROM DUAL" bit can be omitted in Postgresql. There may be small differences, but that is the basic idea. Bèrto -- ==

Re: [SQL] using a generated series in function

2011-12-17 Thread David Johnston
>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 s

Re: [SQL] using a generated series in function

2011-12-17 Thread Adrian Klaver
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()

Re: [SQL] using a generated series in function

2011-12-17 Thread John Fabiani
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 ques

Re: [SQL] using a generated series in function

2011-12-16 Thread Adrian Klaver
On Friday, December 16, 2011 3:56:48 am John Fabiani wrote: > I have solved my problem. But this still does not explain the idea of > "from" From original query: ..(function_name(303, week_date::date)) as week_date where week_date.. Reason why that did not work: http://www.postgresql.org/doc

Re: [SQL] using a generated series in function

2011-12-16 Thread Misa Simic
That is good - that you solved it... Well - in from it does not need to be just from table... it needs to be some set of rows... is it Table or function (SELECT i FROM generate_series(0, 84, 7) i - is actually from function...) or from View... SELECT * FROM (SELECT * FROM Table1) as InlineView

Re: [SQL] using a generated series in function

2011-12-16 Thread Misa Simic
Hi John, Well, maybe the best would be to say on english what you want to achieve... >From SQL code in your mail - it is not clear ( at least to me...) but: SELECT now() - it will just execute function ant there is not possible to say WHERE in that... and like you said: *select function_name(i

Re: [SQL] using a generated series in function

2011-12-16 Thread John Fabiani
I have solved my problem. But this still does not explain the idea of "from" 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

Re: [SQL] using a generated series in function

2011-12-16 Thread John Fabiani
Actually what would the "from" be - this could be a newbie issue here? Neither statement requires a "from" because neither of the statements uses a table - I think! I'll try to add one but the first part is a function like a any other function. What is the "from" when you do: "select now()"

Re: [SQL] using a generated series in function

2011-12-16 Thread Misa Simic
It is not totally clear to me what are u trying to do... But in second query it seems there is missing "from" It is as SELECT week-date::date AS week-date WHERE week-date in (subquery which have from) So week-date column in main query does not exist.. Sent from my Windows Phone From: John Fabia

Re: [SQL] using a generated series in function

2011-12-15 Thread David Johnston
On Dec 15, 2011, at 23:16, John Fabiani wrote: > Hi, > > I am attempting (without success) use the generated series of dates that come > from: > select (cast(date_trunc('week', '2011-11-20'::date ) as date) + (i+6)) as > week_date from generate_series(0,84,7) i > > in a function. > select fu