Thread: Error in executing plpgsql function

Error in executing plpgsql function

From
ananthreddy@yahoo.com (ananth)
Date:
Hi Everyone,

I am newbie and writing a plpgsql function. I have included source
code here for function. When I execute this function where it finds a
row in table it works fine and gives expected output.

The problem is when I run this function by passing a parameter values
where row does not exist in table. I expect it to print message and
return false. Instead it disconnects from server and throughs lot of
errors in log file. Here is output from executing this function

====When row is found======

called from psql

test=# select func1('2');
NOTICE:  Value of ID  2
NOTICE:  Value of NDI1 
NOTICE:  Value of CSSG 5007
NOTICE:  Value of Interval Dischargefunc1 
-------t
(1 row)

======when row is not found=====


test=# select func1('99');
pqReadData() -- backend closed the channel unexpectedly.       This probably means the backend terminated abnormally
  before or while processing the request.
 
The connection to the server was lost. Attempting reset: Failed.
!#

=====also i see following errors in server logfile===
Server process (pid 21536) exited with status 139 at Fri Nov 30
22:28:57 2001
Terminating any active server processes...
Server processes were terminated at Fri Nov 30 22:28:57 2001
Reinitializing shared memory and semaphores
The Data Base System is starting up
DEBUG:  database system was interrupted at 2001-11-30 22:06:39 PST
DEBUG:  CheckPoint record at (0, 185703020)
DEBUG:  Redo record at (0, 185703020); Undo record at (0, 0); Shutdown
TRUE
DEBUG:  NextTransactionId: 2177; NextOid: 1034695
DEBUG:  database system was not properly shut down; automatic recovery
in progress...
DEBUG:  ReadRecord: record with zero len at (0, 185703084)
DEBUG:  redo is not required
DEBUG:  database system is in production state


Any idea what is happeing?
Appreciate any help?
BTW- where can I find good documentation on plpgsql functions?

TIA

ananth


=======Function code========

DROP FUNCTION func1(text);
create function func1(text) returns bool as '
declare  key alias for $1;  ndiraw_rec ndiraw%rowtype;

begin  select into ndiraw_rec * from ndiraw         where ID=key;  if not found then     raise notice ''Record Not
foundfor key %'', key;     return false;  end if;  raise notice ''Value of ID  %'', ndiraw_rec.ID ;  raise notice
''Valueof NDI1 %'',ndiraw_rec.NDI1;  raise notice ''Value of CSSG %'',ndiraw_rec.cssg;  raise notice ''Value of
Interval%'',ndiraw_rec.interval;  return true;
 
end;
' language 'plpgsql'

==========================================


Re: Error in executing plpgsql function

From
Tom Lane
Date:
ananthreddy@yahoo.com (ananth) writes:
> The problem is when I run this function by passing a parameter values
> where row does not exist in table. I expect it to print message and
> return false. Instead it disconnects from server and throughs lot of
> errors in log file. Here is output from executing this function

What PG version are you running?  I seem to recall that there was a bug
with some not-found cases in plpgsql a while back.  If you're not using
7.1.3, update.
        regards, tom lane


Re: Error in executing plpgsql function

From
ananthreddy@yahoo.com (ananth)
Date:
tgl@sss.pgh.pa.us (Tom Lane) wrote in message news:<18422.1007407387@sss.pgh.pa.us>...
> ananthreddy@yahoo.com (ananth) writes:
> > The problem is when I run this function by passing a parameter values
> > where row does not exist in table. I expect it to print message and
> > return false. Instead it disconnects from server and throughs lot of
> > errors in log file. Here is output from executing this function
> 
> What PG version are you running?  I seem to recall that there was a bug
> with some not-found cases in plpgsql a while back.  If you're not using
> 7.1.3, update.

I am running 7.1.1.
Thanks. I'll update.

> 
>             regards, tom lane
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org