X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id AAD98D1B513 for ; Sun, 28 Sep 2003 01:28:40 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 36835-06 for ; Sat, 27 Sep 2003 22:28:33 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id E3C40D1B4E6 for ; Sat, 27 Sep 2003 22:28:29 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id h8S1SX6c003489; Sat, 27 Sep 2003 21:28:33 -0400 (EDT) To: Jan Wieck Cc: pgsql-hackers@postgresql.org Subject: Re: [SQL] plpgsql doesn't coerce boolean expressions to boolean In-reply-to: <3F5E84CF.6090706@Yahoo.com> References: <15403.1063035632@sss.pgh.pa.us> <3F5E0A5D.2010803@Yahoo.com> <3559.1063128729@sss.pgh.pa.us> <3F5E84CF.6090706@Yahoo.com> Comments: In-reply-to Jan Wieck message dated "Tue, 09 Sep 2003 21:56:31 -0400" Date: Sat, 27 Sep 2003 21:28:33 -0400 Message-ID: <3487.1064712513@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/1456 X-Sequence-Number: 44468 Jan Wieck writes: > Tom Lane wrote: >>> 4. Use the parser's coerce_to_boolean procedure, so that nonbooleans >>> will be accepted in exactly the same cases where they'd be accepted >>> in a boolean-requiring SQL construct (such as CASE). (By default, >>> none are, so this isn't really different from #2. But people could >>> create casts to boolean to override this behavior in a controlled >>> fashion.) > Agreed - #4. My first attempt at doing this failed to pass the regression tests, because it wasn't prepared for this: if count(*) = 0 from Room where roomno = new.roomno then raise exception ''Room % does not exist'', new.roomno; end if; Is this really intended to be a feature? It manages to work because plpgsql simply sticks "SELECT " in front of whatever appears between IF and THEN, and passes the result to the main SQL engine. But it sure surprised the heck out of me. The documentation gives no hint that you're allowed to write anything but a straight boolean expression in IF. Does Oracle allow that sort of thing? I would be inclined to think that a more reasonable expression of the intent would be if (select count(*) from Room where roomno = new.roomno) = 0 then Certainly we'd have a big problem supporting the existing coding if we ever reimplement plpgsql with more awareness of what expressions are. regards, tom lane