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 36F70D1B526 for ; Sun, 28 Sep 2003 16:02:55 +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 73969-02 for ; Sun, 28 Sep 2003 13:02:45 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 8990AD1B523 for ; Sun, 28 Sep 2003 13:02:44 -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 h8SG2i6c009352; Sun, 28 Sep 2003 12:02:44 -0400 (EDT) To: Jan Wieck Cc: pgsql-hackers@postgresql.org Subject: Re: [SQL] plpgsql doesn't coerce boolean expressions to In-reply-to: <3F765672.2020304@Yahoo.com> References: <15403.1063035632@sss.pgh.pa.us> <3F5E0A5D.2010803@Yahoo.com> <3559.1063128729@sss.pgh.pa.us> <3F5E84CF.6090706@Yahoo.com> <3487.1064712513@sss.pgh.pa.us> <3F765672.2020304@Yahoo.com> Comments: In-reply-to Jan Wieck message dated "Sat, 27 Sep 2003 23:33:06 -0400" Date: Sun, 28 Sep 2003 12:02:43 -0400 Message-ID: <9351.1064764963@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/1466 X-Sequence-Number: 44478 Jan Wieck writes: > Tom Lane wrote: >> 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? > I have to admit it was less an intention than more a side effect of the > actual implementation. It was so easy to simply stick "SELECT " in front > of "everything between IF and THEN" and expect the result to be a boolean. Sure, it was easy given a certain implementation technique. Question is, do we want to consider it a supported feature even if it makes the implementation hard? > In the same way you can do > varname := count(*) from Room where roomno = new.roomno; This actually doesn't bother me; I see it as simply a variant syntax for SELECT INTO. (Perhaps it should be documented that way.) If we want to preserve this behavior for IF et al, I don't think there is any practical way to apply SQL-level type coercion as I had wanted. We could instead make the code act like it's assigning to a plpgsql boolean variable --- but it will apply plpgsql's textual conversion methods, not SQL type coercion. regards, tom lane