Re: [SQL] DIfference between max() and greatest() ?

2008-09-12 Thread Ruben Gouveia
< current_date - interval '1 day' ... > would be enough. > Another thought: with this WHERE clause a car returned yesterday will not > show up. > Is that what you want? If not, use > ... WHERE max(returned) < current_date ... > > Good luck > > > &

[SQL] DIfference between max() and greatest() ?

2008-09-11 Thread Ruben Gouveia
What is the difference between these two. I know that max() is an aggregate function select model,count(distinct cars) from rc_cars where greatest(baught,returned) < current_date - integer '1' group by model; Do i need to have a max () around a greatest() to make sure i get the most recent of the

[SQL] Aggregates in WHERE clause?

2008-09-10 Thread Ruben Gouveia
I tried to do the following and got the following error message: select employee,count(distinct tasks) from job where greatest(max(last_job_date),max(last_position_date)) < 2008-08-28 + integer '1' group by employee; ERROR: aggregates not allowed in WHERE clause

Re: [SQL] Function Syntax involving pipes and ' marks?

2008-09-10 Thread Ruben Gouveia
Is that more expensive to run than just useing a bunch of ticks? Sent from Apple iPhone 3G On Sep 10, 2008, at 11:24 AM, Bricklen Anderson <[EMAIL PROTECTED]> wrote: Ruben Gouveia wrote: v_where varchar(256) := 'where m.jb_date < '||p_

Re: [SQL] Function Syntax involving pipes and ' marks?

2008-09-10 Thread Ruben Gouveia
i will try that. thank you On Wed, Sep 10, 2008 at 11:45 AM, Tom Lane <[EMAIL PROTECTED]> wrote: > Bricklen Anderson <[EMAIL PROTECTED]> writes: > > Ruben Gouveia wrote: > >> Is that more expensive to run than just useing a bunch of ticks? > > > I pers

[SQL] Function Syntax involving pipes and ' marks?

2008-09-09 Thread Ruben Gouveia
No matter how many times i try, i can't seem to get the write amount of ' marks around the date parameters in my v_where declaration. What am i doing wrong here? v_stmt should look like this if done correctly: select count(distinct m.id) from (select id, greatest(max(last_p),max(last_b)) as date_

Re: [SQL] Function syntax ?

2008-09-09 Thread Ruben Gouveia
It appears there is already a greatest() and least() function available...so no need for creating this function. On Tue, Sep 9, 2008 at 11:16 AM, Ruben Gouveia <[EMAIL PROTECTED]> wrote: > thanks pavel...that worked! I like the simplicity of your first suggestion. > > > On Tue,

Re: [SQL] Function syntax ?

2008-09-09 Thread Ruben Gouveia
dt; > else >return p_dt2; > end if; > end; > $$ language sql; > > plpgsql is scripting language and almost is better minimalize number > of statements in function. > > Regards > Pavel Stehule > > 2008/9/9 Ruben Gouveia <[EMAIL PROTECTED]>: > >

Re: [SQL] Function syntax ?

2008-09-09 Thread Ruben Gouveia
** ERROR: syntax error at or near "v_dt" SQL state: 42601 Context: SQL statement in PL/PgSQL function "fcn_max_dt" near line 3 On Tue, Sep 9, 2008 at 11:07 AM, Scott Marlowe <[EMAIL PROTECTED]>wrote: > On Tue, Sep 9, 2008 at 11:55 AM, Ruben Gouveia <[

[SQL] Function syntax ?

2008-09-09 Thread Ruben Gouveia
Does this syntax look correct? Can anyone think of a better way to write this? This function will accept two timestamp parameters and determine the highest of the two? create or replace function fcn_max_dt(p_dt timestamp without time zone, p_dt2 timestamp wit

[SQL] PL/pgSQL function syntax question?

2008-09-08 Thread Ruben Gouveia
i get the following error when i try and create the following function: Basically, i am trying to have two different dates compared and only the most recent returned to me. This seems pretty straight forward, what I am doing wrong here? create or replace function fcn_pick_date(v_dt date) returns

Re: [SQL] Correct Insert SQL syntax?

2008-09-04 Thread Ruben Gouveia
Thanks Yuri! On Thu, Sep 4, 2008 at 3:49 PM, Yura Gal <[EMAIL PROTECTED]> wrote: > There is no internal dual table in PG unlike Ora:) If you need to > invoke non-set-returning function simply execute: > > SELECT my_func(p1, p2...); > > -- > Best regards, Yuri. >

[SQL] Correct Insert SQL syntax?

2008-09-04 Thread Ruben Gouveia
Will this syntax work: fcn_stats are all in the same schema CREATE OR REPLACE FUNCTION insert_stats(p_date date) RETURNS void AS $$ BEGIN insert into stats ( date, stats1, stats2

Re: [SQL] Dynamic SQL Syntax help please

2008-09-04 Thread Ruben Gouveia
thank you Sergio. I decided to use EXECUTE v_stmt into v_total_pop; On Thu, Sep 4, 2008 at 2:00 PM, Ivan Sergio Borgonovo <[EMAIL PROTECTED]>wrote: > On Thu, 4 Sep 2008 13:41:16 -0700 > "Ruben Gouveia" <[EMAIL PROTECTED]> wrote: > > > I created a simpl

[SQL] Dynamic SQL Syntax help please

2008-09-04 Thread Ruben Gouveia
I created a simple function that i want to use another function (in the same schema) that will be used to create a sql statement. I get the following error when i try this: *ERROR: syntax error at or near "EXEC" at character 1 QUERY: EXEC SQL EXECUTE $1 INTO $2 CONTEXT: SQL statement in PL/P

Re: [SQL] Syntax help please

2008-09-04 Thread Ruben Gouveia
; >v_where := p_where<--- missing ; here > v_stmt := c_select || v_from || v_where; > > Regards, > Fernando > > > > > > De: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] En nombre de Rube

[SQL] Syntax help please

2008-09-04 Thread Ruben Gouveia
I can't for the life of me figure out what's wrong with this syntax. I get the following error when i try and create this function. *ERROR: syntax error at or near "$2" at character 15 QUERY: SELECT $1 $2 := $3 || $4 || $5 CONTEXT: SQL statement in PL/PgSQL function "fcn_gen_statement