pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Function Syntax Help
6+ messages / 3 participants
[nested] [flat]

* Function Syntax Help
@ 2009-10-30 19:14 Plugge, Joe R. <JRPlugge@west.com>
  2009-10-30 19:29 ` Re: Function Syntax Help Brian Modra <brian@zwartberg.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Plugge, Joe R. @ 2009-10-30 19:14 UTC (permalink / raw)
  To: pgsql-sql

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) AS $$ DECLARE

    mycount integer;

BEGIN

    WHILE mystart < mystop + INTERVAL '1 day' LOOP

    SELECT INTO mycount  count(*) FROM log_calls WHERE startdate < mystart and enddate > mystop;

    INSERT INTO simultaneous_calls_rpt (startdate,call_count) VALUES (mystart,mycount);

    mystart := mystart + INTERVAL '1 minute';

    mystop  := mystop + INTERVAL '1 minute';

    END LOOP;

END;

    $$ LANGUAGE 'plpgsql' STABLE;








[cid:image002.jpg@01CA596B.59B9EC10]Joe R. Plugge
Database Administrator, West Interactive Corporation
11650 Miracle Hills Drive, Omaha NE 68154
402-716-0349 | Cell 402-517-2710 | jrplugge@west.com

This electronic message transmission, including any attachments, contains information from West Corporation which may be confidential or privileged. The information is intended to be for the use of the individual or entity named above. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited.

If you have received this electronic transmission in error, please notify the sender immediately by a "reply to sender only" message and destroy all electronic and hard copies of the communication, including attachments.

Attachments:

image001.png (image/png, 827B) download view image
image002.jpg (image/jpeg, 1.7K) download view image
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: Function Syntax Help
  2009-10-30 19:14 Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
@ 2009-10-30 19:29 ` Brian Modra <brian@zwartberg.com>
  2009-10-30 19:30   ` Re: Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Brian Modra @ 2009-10-30 19:29 UTC (permalink / raw)
  To: Plugge, Joe R. <JRPlugge@west.com>; +Cc: pgsql-sql

2009/10/30 Plugge, Joe R. <JRPlugge@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 gen_simultaneous_calls(mystart timestamp, mystop timestamp)
> AS $$ DECLARE
>
>
you need to tell it the return type. If there is none, "returns void"

e.g.
 CREATE FUNCTION gen_simultaneous_calls(mystart timestamp, mystop timestamp)
returns void AS $$

>     mycount integer;
>
> BEGIN
>
>     WHILE mystart < mystop + INTERVAL '1 day' LOOP
>
>     SELECT INTO mycount  count(*) FROM log_calls WHERE startdate < mystart
> and enddate > mystop;
>
>     INSERT INTO simultaneous_calls_rpt (startdate,call_count) VALUES
> (mystart,mycount);
>
>     mystart := mystart + INTERVAL '1 minute';
>
>     mystop  := mystop + INTERVAL '1 minute';
>
>     END LOOP;
>
> END;
>
>     $$ LANGUAGE 'plpgsql' STABLE;
>
>
>
>
>
>
>
>
>
>
>
> [image: image001]*Joe R. Plugge*
>
> *Database Administrator, West Interactive Corporation*
>
> *11650 Miracle Hills Drive, Omaha NE 68154*
>
> *402-716-0349 | Cell 402-517-2710 | jrplugge@west.com** *
>
>
>
> *This electronic message transmission, including any attachments, contains
> information from West Corporation which may be confidential or privileged.
> The information is intended to be for the use of the individual or entity
> named above. If you are not the intended recipient, be aware that any
> disclosure, copying, distribution or use of the contents of this information
> is prohibited. *
>
> * *
>
> *If you have received this electronic transmission in error, please notify
> the sender immediately by a "reply to sender only" message and destroy all
> electronic and hard copies of the communication, including attachments.*
>



-- 
Brian Modra   Land line: +27 23 5411 462
Mobile: +27 79 69 77 082
5 Jan Louw Str, Prince Albert, 6930
Postal: P.O. Box 2, Prince Albert 6930
South Africa
http://www.zwartberg.com/

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Function Syntax Help
  2009-10-30 19:14 Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
  2009-10-30 19:29 ` Re: Function Syntax Help Brian Modra <brian@zwartberg.com>
@ 2009-10-30 19:30   ` Plugge, Joe R. <JRPlugge@west.com>
  2009-10-30 19:45     ` Re: Function Syntax Help Brian Modra <brian@zwartberg.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Plugge, Joe R. @ 2009-10-30 19:30 UTC (permalink / raw)
  To: Brian Modra <brian@zwartberg.com>; +Cc: pgsql-sql

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 enddate > mystop;
    INSERT INTO simultaneous_calls_rpt (startdate,call_count) VALUES (mystart,mycount);
    mystart := mystart + INTERVAL '1 minute';
    mystop  := mystop + INTERVAL '1 minute';
    END LOOP;
END;
    $$ LANGUAGE 'plpgsql' STABLE;

But now am getting a different error:

[postgres@linux1559 ~]$ cat gen_simultaneous_calls.sql | psql holly
ERROR:  "$1" is declared CONSTANT
CONTEXT:  compilation of PL/pgSQL function "gen_simultaneous_calls" near line 7



From: epailty@googlemail.com [mailto:epailty@googlemail.com] On Behalf Of Brian Modra
Sent: Friday, October 30, 2009 2:29 PM
To: Plugge, Joe R.
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Function Syntax Help

2009/10/30 Plugge, Joe R. <JRPlugge@west.com<mailto:JRPlugge@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 gen_simultaneous_calls(mystart timestamp, mystop timestamp) AS $$ DECLARE

you need to tell it the return type. If there is none, "returns void"

e.g.
 CREATE FUNCTION gen_simultaneous_calls(mystart timestamp, mystop timestamp) returns void AS $$

    mycount integer;

BEGIN

    WHILE mystart < mystop + INTERVAL '1 day' LOOP

    SELECT INTO mycount  count(*) FROM log_calls WHERE startdate < mystart and enddate > mystop;

    INSERT INTO simultaneous_calls_rpt (startdate,call_count) VALUES (mystart,mycount);

    mystart := mystart + INTERVAL '1 minute';

    mystop  := mystop + INTERVAL '1 minute';

    END LOOP;

END;

    $$ LANGUAGE 'plpgsql' STABLE;








Joe R. Plugge
Database Administrator, West Interactive Corporation
11650 Miracle Hills Drive, Omaha NE 68154
402-716-0349 | Cell 402-517-2710 | jrplugge@west.com<mailto:jrplugge@west.com>

This electronic message transmission, including any attachments, contains information from West Corporation which may be confidential or privileged. The information is intended to be for the use of the individual or entity named above. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited.

If you have received this electronic transmission in error, please notify the sender immediately by a "reply to sender only" message and destroy all electronic and hard copies of the communication, including attachments.



--
Brian Modra   Land line: +27 23 5411 462
Mobile: +27 79 69 77 082
5 Jan Louw Str, Prince Albert, 6930
Postal: P.O. Box 2, Prince Albert 6930
South Africa
http://www.zwartberg.com/

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Function Syntax Help
  2009-10-30 19:14 Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
  2009-10-30 19:29 ` Re: Function Syntax Help Brian Modra <brian@zwartberg.com>
  2009-10-30 19:30   ` Re: Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
@ 2009-10-30 19:45     ` Brian Modra <brian@zwartberg.com>
  2009-10-30 19:50       ` Re: Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Brian Modra @ 2009-10-30 19:45 UTC (permalink / raw)
  To: Plugge, Joe R. <JRPlugge@west.com>; +Cc: pgsql-sql

2009/10/30 Plugge, Joe R. <JRPlugge@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 mycount  count(*) FROM log_calls WHERE startdate < mystart
> and enddate > mystop;
>
>     INSERT INTO simultaneous_calls_rpt (startdate,call_count) VALUES
> (mystart,mycount);
>
>     mystart := mystart + INTERVAL '1 minute';
>
>     mystop  := mystop + INTERVAL '1 minute';
>
>     END LOOP;
>
> END;
>
>     $$ LANGUAGE 'plpgsql' STABLE;
>
>
>
> But now am getting a different error:
>
>
>
> [postgres@linux1559 ~]$ cat gen_simultaneous_calls.sql | psql holly
>
> ERROR:  "$1" is declared CONSTANT
>
> CONTEXT:  compilation of PL/pgSQL function "gen_simultaneous_calls" near
> line 7
>
>
 mystart and mystop are constants...

you could declare variables and copy those into them, and the modify the new
variables...

>
>
>
>
>
>
> *From:* epailty@googlemail.com [mailto:epailty@googlemail.com] *On Behalf
> Of *Brian Modra
> *Sent:* Friday, October 30, 2009 2:29 PM
> *To:* Plugge, Joe R.
> *Cc:* pgsql-sql@postgresql.org
> *Subject:* Re: [SQL] Function Syntax Help
>
>
>
> 2009/10/30 Plugge, Joe R. <JRPlugge@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 gen_simultaneous_calls(mystart timestamp, mystop timestamp)
> AS $$ DECLARE
>
>
> you need to tell it the return type. If there is none, "returns void"
>
> e.g.
>  CREATE FUNCTION gen_simultaneous_calls(mystart timestamp, mystop
> timestamp) returns void AS $$
>
>      mycount integer;
>
> BEGIN
>
>     WHILE mystart < mystop + INTERVAL '1 day' LOOP
>
>     SELECT INTO mycount  count(*) FROM log_calls WHERE startdate < mystart
> and enddate > mystop;
>
>     INSERT INTO simultaneous_calls_rpt (startdate,call_count) VALUES
> (mystart,mycount);
>
>     mystart := mystart + INTERVAL '1 minute';
>
>     mystop  := mystop + INTERVAL '1 minute';
>
>     END LOOP;
>
> END;
>
>     $$ LANGUAGE 'plpgsql' STABLE;
>
>
>
>
>
>
>
>
>
>
>
> [image: image001]*Joe R. Plugge*
>
> *Database Administrator, West Interactive Corporation*
>
> *11650 Miracle Hills Drive, Omaha NE 68154*
>
> *402-716-0349 | Cell 402-517-2710 | jrplugge@west.com** *
>
>
>
> *This electronic message transmission, including any attachments, contains
> information from West Corporation which may be confidential or privileged.
> The information is intended to be for the use of the individual or entity
> named above. If you are not the intended recipient, be aware that any
> disclosure, copying, distribution or use of the contents of this information
> is prohibited. *
>
> * *
>
> *If you have received this electronic transmission in error, please notify
> the sender immediately by a "reply to sender only" message and destroy all
> electronic and hard copies of the communication, including attachments.*
>
>
>
>
> --
> Brian Modra   Land line: +27 23 5411 462
> Mobile: +27 79 69 77 082
> 5 Jan Louw Str, Prince Albert, 6930
> Postal: P.O. Box 2, Prince Albert 6930
> South Africa
> http://www.zwartberg.com/
>



-- 
Brian Modra   Land line: +27 23 5411 462
Mobile: +27 79 69 77 082
5 Jan Louw Str, Prince Albert, 6930
Postal: P.O. Box 2, Prince Albert 6930
South Africa
http://www.zwartberg.com/

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Function Syntax Help
  2009-10-30 19:14 Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
  2009-10-30 19:29 ` Re: Function Syntax Help Brian Modra <brian@zwartberg.com>
  2009-10-30 19:30   ` Re: Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
  2009-10-30 19:45     ` Re: Function Syntax Help Brian Modra <brian@zwartberg.com>
@ 2009-10-30 19:50       ` Plugge, Joe R. <JRPlugge@west.com>
  2009-10-30 21:22         ` Re: Function Syntax Help Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 6+ messages in thread

From: Plugge, Joe R. @ 2009-10-30 19:50 UTC (permalink / raw)
  To: Brian Modra <brian@zwartberg.com>; +Cc: pgsql-sql

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
    WHILE newstart < newstop + INTERVAL '1 day' LOOP
    SELECT INTO mycount  count(*) FROM log_calls WHERE startdate < newstart and enddate > newstop;
    INSERT INTO simultaneous_calls_rpt (startdate,call_count) VALUES (newstart,mycount);
    newstart := newstart + INTERVAL '1 minute';
    newstop  := newstop + INTERVAL '1 minute';
    END LOOP;
END;
    $$ LANGUAGE 'plpgsql' VOLATILE;



From: epailty@googlemail.com [mailto:epailty@googlemail.com] On Behalf Of Brian Modra
Sent: Friday, October 30, 2009 2:46 PM
To: Plugge, Joe R.
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Function Syntax Help

2009/10/30 Plugge, Joe R. <JRPlugge@west.com<mailto:JRPlugge@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 mycount  count(*) FROM log_calls WHERE startdate < mystart and enddate > mystop;
    INSERT INTO simultaneous_calls_rpt (startdate,call_count) VALUES (mystart,mycount);
    mystart := mystart + INTERVAL '1 minute';
    mystop  := mystop + INTERVAL '1 minute';
    END LOOP;
END;
    $$ LANGUAGE 'plpgsql' STABLE;

But now am getting a different error:

[postgres@linux1559 ~]$ cat gen_simultaneous_calls.sql | psql holly
ERROR:  "$1" is declared CONSTANT
CONTEXT:  compilation of PL/pgSQL function "gen_simultaneous_calls" near line 7

 mystart and mystop are constants...

you could declare variables and copy those into them, and the modify the new variables...



From: epailty@googlemail.com<mailto:epailty@googlemail.com> [mailto:epailty@googlemail.com<mailto:epailty@googlemail.com>] On Behalf Of Brian Modra
Sent: Friday, October 30, 2009 2:29 PM
To: Plugge, Joe R.
Cc: pgsql-sql@postgresql.org<mailto:pgsql-sql@postgresql.org>
Subject: Re: [SQL] Function Syntax Help

2009/10/30 Plugge, Joe R. <JRPlugge@west.com<mailto:JRPlugge@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 gen_simultaneous_calls(mystart timestamp, mystop timestamp) AS $$ DECLARE

you need to tell it the return type. If there is none, "returns void"

e.g.
 CREATE FUNCTION gen_simultaneous_calls(mystart timestamp, mystop timestamp) returns void AS $$

    mycount integer;

BEGIN

    WHILE mystart < mystop + INTERVAL '1 day' LOOP

    SELECT INTO mycount  count(*) FROM log_calls WHERE startdate < mystart and enddate > mystop;

    INSERT INTO simultaneous_calls_rpt (startdate,call_count) VALUES (mystart,mycount);

    mystart := mystart + INTERVAL '1 minute';

    mystop  := mystop + INTERVAL '1 minute';

    END LOOP;

END;

    $$ LANGUAGE 'plpgsql' STABLE;








Joe R. Plugge
Database Administrator, West Interactive Corporation
11650 Miracle Hills Drive, Omaha NE 68154
402-716-0349 | Cell 402-517-2710 | jrplugge@west.com<mailto:jrplugge@west.com>

This electronic message transmission, including any attachments, contains information from West Corporation which may be confidential or privileged. The information is intended to be for the use of the individual or entity named above. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited.

If you have received this electronic transmission in error, please notify the sender immediately by a "reply to sender only" message and destroy all electronic and hard copies of the communication, including attachments.



--
Brian Modra   Land line: +27 23 5411 462
Mobile: +27 79 69 77 082
5 Jan Louw Str, Prince Albert, 6930
Postal: P.O. Box 2, Prince Albert 6930
South Africa
http://www.zwartberg.com/



--
Brian Modra   Land line: +27 23 5411 462
Mobile: +27 79 69 77 082
5 Jan Louw Str, Prince Albert, 6930
Postal: P.O. Box 2, Prince Albert 6930
South Africa
http://www.zwartberg.com/

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Function Syntax Help
  2009-10-30 19:14 Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
  2009-10-30 19:29 ` Re: Function Syntax Help Brian Modra <brian@zwartberg.com>
  2009-10-30 19:30   ` Re: Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
  2009-10-30 19:45     ` Re: Function Syntax Help Brian Modra <brian@zwartberg.com>
  2009-10-30 19:50       ` Re: Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
@ 2009-10-30 21:22         ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2009-10-30 21:22 UTC (permalink / raw)
  To: Plugge, Joe R. <JRPlugge@west.com>; +Cc: Brian Modra <brian@zwartberg.com>; pgsql-sql

"Plugge, Joe R." <JRPlugge@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?

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2009-10-30 21:22 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-10-30 19:14 Function Syntax Help Plugge, Joe R. <JRPlugge@west.com>
2009-10-30 19:29 ` Brian Modra <brian@zwartberg.com>
2009-10-30 19:30   ` Plugge, Joe R. <JRPlugge@west.com>
2009-10-30 19:45     ` Brian Modra <brian@zwartberg.com>
2009-10-30 19:50       ` Plugge, Joe R. <JRPlugge@west.com>
2009-10-30 21:22         ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox