X-Original-To: pgsql-docs-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 77E32D1B440 for ; Mon, 1 Dec 2003 21:55:04 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 98254-01 for ; Mon, 1 Dec 2003 17:54:37 -0400 (AST) Received: from candle.pha.pa.us (unknown [207.106.42.251]) by svr1.postgresql.org (Postfix) with ESMTP id 86E77D1D38B for ; Mon, 1 Dec 2003 17:54:34 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id hB1LsSn15127; Mon, 1 Dec 2003 16:54:28 -0500 (EST) From: Bruce Momjian Message-Id: <200312012154.hB1LsSn15127@candle.pha.pa.us> Subject: Re: [PATCHES] Numeric version of factorial() In-Reply-To: To: Gavin Sherry Date: Mon, 1 Dec 2003 16:54:28 -0500 (EST) Cc: PostgreSQL-documentation X-Mailer: ELM [version 2.4ME+ PL108 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=ELM1070315668-12018-1_ Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/10 X-Sequence-Number: 2170 --ELM1070315668-12018-1_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII I had to remove the factorial example from the casting docs because factorial is now defined only for numeric. Would someone take the attached example and make a new one with a different operator? Thanks. --------------------------------------------------------------------------- Gavin Sherry wrote: > Attached is a patch implementing factorial(), returning numeric. Points to > note: > > 1) arttype is numeric. I thought this was the best way of allowing > arbitarily large factorials, even though factorial(2^63) is a large > number. Happy to change to integers if this is overkill. > 2) since we're accepting numeric arguments, the patch tests for floats. If > a numeric is passed with non-zero decimal portion, an error is raised > since (from memory) they are undefined. > 3) I have not removed factorial([int2|int4|int8]), not their operator > counterparts since I didn't know what people would want done with these. > 4) I haven't added any documentation but am happy to once I know if people > want int or numeric arguments. > > Thanks, > > Gavin Content-Description: [ Attachment, skipping... ] > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 --ELM1070315668-12018-1_ Content-Transfer-Encoding: 7bit Content-Type: text/plain Content-Disposition: inline; filename="/pgpatches/factorial" Index: doc/src/sgml/typeconv.sgml =================================================================== RCS file: /cvsroot/pgsql-server/doc/src/sgml/typeconv.sgml,v retrieving revision 1.39 diff -c -c -r1.39 typeconv.sgml *** doc/src/sgml/typeconv.sgml 29 Nov 2003 19:51:38 -0000 1.39 --- doc/src/sgml/typeconv.sgml 1 Dec 2003 21:42:04 -0000 *************** *** 437,466 **** ERROR: "-4.5e500" is out of range for type double precision - - - On the other hand, the postfix operator ! (factorial) - is defined only for integer data types, not for float8. So, if we - try a similar case with !, we get: - - SELECT '20' ! AS "factorial"; - - ERROR: operator is not unique: "unknown" ! - HINT: Could not choose a best candidate operator. You may need to add explicit - type casts. - - This happens because the system can't decide which of the several - possible ! operators should be preferred. We can help - it out with an explicit cast: - - SELECT CAST('20' AS int8) ! AS "factorial"; - - factorial - --------------------- - 2432902008176640000 - (1 row) - - --- 437,442 ---- --ELM1070315668-12018-1_--