dbTalk Databases Forums  

Script done... Function won´t work...

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Script done... Function won´t work... in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Marcel Boscher
 
Posts: n/a

Default Script done... Function won´t work... - 08-10-2004 , 10:08 AM






Once again, ;-)

The script is finally done i hope ...

i can create my function.... no problem
but when i'm calling it up with a
SELECT zufall(); statement pgAdmin
tells me there is no function with that name...
although its listed in my function list as zufall!!!! ...
<runningagainstthewallheadfirst>


SOURCE:
create or replace function zufall(int4) returns text as '
declare
anzahl alias for $1;
i int4;
zeichen char(1);
zufallstext text;
entries int8;
begin
loop
zufallstext := '''';
for i in 1..anzahl loop
select chr(trunc((random()*26)+65)) into zeichen;
zufallstext := zufallstext || zeichen;
end loop;
SELECT count(*) into entries FROM se_errorcode
WHERE entry = zufallstext;
EXIT WHEN entries = 0;
end loop;
return zufallstext;
end;
' language 'plpgsql';


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
  #2  
Old   
Ron St-Pierre
 
Posts: n/a

Default Re: Script done... Function won´t wo - 08-10-2004 , 11:03 AM






Marcel Boscher wrote:

Quote:
Once again, ;-)

The script is finally done i hope ...

i can create my function.... no problem
but when i'm calling it up with a
SELECT zufall(); statement pgAdmin
tells me there is no function with that name...
although its listed in my function list as zufall!!!! ...
runningagainstthewallheadfirst


SOURCE:
create or replace function zufall(int4) returns text as '
declare
anzahl alias for $1;
i int4;
zeichen char(1);
zufallstext text;
entries int8;
begin
loop
zufallstext := '''';
for i in 1..anzahl loop
select chr(trunc((random()*26)+65)) into zeichen;
zufallstext := zufallstext || zeichen;
end loop;
SELECT count(*) into entries FROM se_errorcode
WHERE entry = zufallstext;
EXIT WHEN entries = 0;
end loop;
return zufallstext;
end;
' language 'plpgsql';


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


First, make sure that you're passing in an argument:
SELECT zufall(5);

When I try it on my test db (7.4) I get:
testdb=# SELECT zufall(5);
ERROR: function chr(double precision) does not exist
HINT: No function matches the given name and argument types. You may
need to add explicit type casts.
CONTEXT: PL/pgSQL function "zufall" line 11 at select into variables
so you should also check the arguments and return type of the chr()
function.

Hope that helps.

Ron


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
  #3  
Old   
Mike G
 
Posts: n/a

Default Re: Script done. - 08-10-2004 , 11:11 PM



Hello,
I believe you need to call your function as pass an int everytime.

SELECT zufall(0);

If you have multiple databases, not in schema sense, make sure you clicked somewhere on the screen within that database so the sql window points to that database.

Mike

On Tue, Aug 10, 2004 at 05:08:39PM +0200, Marcel Boscher wrote:
Quote:
Once again, ;-)

The script is finally done i hope ...

i can create my function.... no problem
but when i'm calling it up with a
SELECT zufall(); statement pgAdmin
tells me there is no function with that name...
although its listed in my function list as zufall!!!! ...
runningagainstthewallheadfirst


SOURCE:
create or replace function zufall(int4) returns text as '
declare
anzahl alias for $1;
i int4;
zeichen char(1);
zufallstext text;
entries int8;
begin
loop
zufallstext := '''';
for i in 1..anzahl loop
select chr(trunc((random()*26)+65)) into zeichen;
zufallstext := zufallstext || zeichen;
end loop;
SELECT count(*) into entries FROM se_errorcode
WHERE entry = zufallstext;
EXIT WHEN entries = 0;
end loop;
return zufallstext;
end;
' language 'plpgsql';


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.