Re: [SQL] slow count(CASE) query

2009-10-30 Thread Richard Huxton
Grant Masan wrote: select '000100' as length, sum(ship1) as ship1 ,sum(ship2) as ship2,sum(ship3) as ship3,sum(ship4) as ship4,sum(ship5) as ship5 FROM (select count(CASE WHEN (type between 40 and 49) THEN 1 ELSE NULL END) as ship1, count(CASE WHEN (type between 60 and 69) THEN 1 ELSE NULL

[SQL] Function Syntax Help

2009-10-30 Thread Plugge, Joe R.
I am trying to create a function that will grind through a cdr table and populate another table. I am trying to load the function and am getting the following error: ERROR: function result type must be specified CREATE FUNCTION gen_simultaneous_calls(mystart timestamp, mystop timestamp)

Re: [SQL] Function Syntax Help

2009-10-30 Thread Brian Modra
2009/10/30 Plugge, Joe R. jrplu...@west.com I am trying to create a function that will grind through a cdr table and populate another table. I am trying to load the function and am getting the following error: ERROR: function result type must be specified CREATE FUNCTION

Re: [SQL] Function Syntax Help

2009-10-30 Thread Plugge, Joe R.
Thanks Brian, I changed it to this: CREATE FUNCTION gen_simultaneous_calls(mystart timestamp, mystop timestamp) RETURNS VOID AS $$ DECLARE mycount integer; BEGIN WHILE mystart mystop + INTERVAL '1 day' LOOP SELECT INTO mycount count(*) FROM log_calls WHERE startdate mystart and

Re: [SQL] Function Syntax Help

2009-10-30 Thread Brian Modra
2009/10/30 Plugge, Joe R. jrplu...@west.com Thanks Brian, I changed it to this: CREATE FUNCTION gen_simultaneous_calls(mystart timestamp, mystop timestamp) RETURNS VOID AS $$ DECLARE mycount integer; BEGIN WHILE mystart mystop + INTERVAL '1 day' LOOP SELECT INTO

Re: [SQL] Function Syntax Help

2009-10-30 Thread Plugge, Joe R.
Thanks, I changed my code to this, it compiled, and it seems to be running now: CREATE OR REPLACE FUNCTION gen_simultaneous_calls(mystart timestamp, mystop timestamp) RETURNS VOID AS $$ DECLARE mycount integer; newstart timestamp := mystart; newstop timestamp := mystop; BEGIN

Re: [SQL] Function Syntax Help

2009-10-30 Thread Tom Lane
Plugge, Joe R. jrplu...@west.com writes: Thanks, I changed my code to this, it compiled, and it seems to be running now: It looks like you are expecting assignment to the input parameters to do something useful ... it will not. Maybe you need some output parameters?

Re: [SQL] pg_get_functiondef and overloaded functions

2009-10-30 Thread Thomas Kellerer
Tom Lane wrote on 30.10.2009 05:44: select pg_get_functiondef('foo(int)'::regproc) select pg_get_functiondef('foo(int4)'::regproc) select pg_get_functiondef('foo(integer)'::regproc) but each time I get the error: function foo(integer) does not exist What am I missing? You need to use