pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tuttle, Gene <cetuttle@rottlundhomes.com>
To: 'pgsql-admin@postgresql.org' <pgsql-admin@postgresql.org>
Subject: PL/pgsql
Date: Tue, 29 Jun 2004 15:52:37 -0500
Message-ID: <199F7F755B80D511877100B0D0F0B76CC3FDE3@mail.rottlundhomes.com> (raw)

I am new to Postgresql and am having problems getting functions working.

I have been following an example in the book "PostgreSQL" by Douglas &
Douglas Published by Developers Library.
I put the  code in as a function (see end of email)


When I execute it from psql I get the following:
dev=# select my_factorial(1);
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

Can any one help me find the problem.  point me in the right direction?

Thanks
Gene Tuttle




-- Function: public.my_factorial(int4)

-- DROP FUNCTION public.my_factorial(int4);

CREATE OR REPLACE FUNCTION public.my_factorial(int4)
  RETURNS int4 AS
'
  DECLARE
	arg INTEGER;
  BEGIN

	arg := $1;

	IF arg IS NULL or arg < 0 THEN
		RAISE NOTICE \'Invalid Number\';
		RETURN NULL;
	ELSE
		IF arg = 1 THEN
			RETURN 1;
		ELSE
			DECLARE
				next_value INTEGER;
			BEGIN


				next_value := my_factorial(arg - 1) * arg;
				RETURN next_value;
			END;
		END IF;
	END IF;
END;
'
  LANGUAGE 'plpgsql' VOLATILE;



view thread (8+ messages)  latest in thread

Message-ID: <199F7F755B80D511877100B0D0F0B76CC3FDE3@mail.rottlundhomes.com>
Permalink:  ../199F7F755B80D511877100B0D0F0B76CC3FDE3@mail.rottlundhomes.com/
Also on:    postgresql.org/message-id/199F7F755B80D511877100B0D0F0B76CC3FDE3@mail.rottlundhomes.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: cetuttle@rottlundhomes.com
  Subject: Re: PL/pgsql
  In-Reply-To: <199F7F755B80D511877100B0D0F0B76CC3FDE3@mail.rottlundhomes.com>
  References: <199F7F755B80D511877100B0D0F0B76CC3FDE3@mail.rottlundhomes.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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