pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: R. van Twisk <r.vantwisk@jongert.nl>
To: 'Tom Lane' <tgl@sss.pgh.pa.us>
To: pgsql-hackers@postgresql.org
To: pgsql-sql@postgresql.org
Subject: Re: plpgsql doesn't coerce boolean expressions to boolean
Date: Tue, 9 Sep 2003 08:43:47 +0200
Message-ID: <002301c3769d$b988d000$f101000a@IT001> (raw)
In-Reply-To: <15403.1063035632@sss.pgh.pa.us>

I would suggest to throw a error, or at least a warning.

This will FORCE people to program in the correct way.

I also thought that 'IF $1 THEN ...' should work ok but giving it a other
thought it's indeed stuped to write that way (I'm from the C world...)

Ries

-----Oorspronkelijk bericht-----
Van: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org]Namens Tom Lane
Verzonden: maandag 8 september 2003 17:41
Aan: pgsql-hackers@postgresql.org; pgsql-sql@postgresql.org
Onderwerp: [SQL] plpgsql doesn't coerce boolean expressions to boolean


Following up this gripe
http://archives.postgresql.org/pgsql-sql/2003-09/msg00044.php
I've realized that plpgsql just assumes that the test expression
of an IF, WHILE, or EXIT statement is a boolean expression.  It
doesn't take any measures to ensure this is the case or convert
the value if it's not the case.  This seems pretty bogus to me.

However ... with the code as it stands, for pass-by-reference datatypes
any nonnull value will appear TRUE, while for pass-by-value datatypes
any nonzero value will appear TRUE.  I fear that people may actually be
depending on these behaviors, particularly the latter one which is
pretty reasonable if you're accustomed to C.  So while I'd like to throw
an error if the argument isn't boolean, I'm afraid of breaking people's
function definitions.

Here are some possible responses, roughly in order of difficulty
to implement:

1. Leave well enough alone (and perhaps document the behavior).

2. Throw an error if the expression doesn't return boolean.

3. Try to convert nonbooleans to boolean using plpgsql's usual method
   for cross-type coercion, ie run the type's output proc to get a
   string and feed it to bool's input proc.  (This seems unlikely to
   avoid throwing an error in very many cases, but it'd be the most
   consistent with other parts of plpgsql.)

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.)

Any opinions about what to do?

			regards, tom lane

---------------------------(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




view thread (25+ messages)  latest in thread

Message-ID: <002301c3769d$b988d000$f101000a@IT001>
Permalink:  ../002301c3769d$b988d000$f101000a@IT001/
Also on:    postgresql.org/message-id/002301c3769d$b988d000$f101000a@IT001

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: r.vantwisk@jongert.nl, tgl@sss.pgh.pa.us, pgsql-hackers@postgresql.org
  Subject: Re: plpgsql doesn't coerce boolean expressions to boolean
  In-Reply-To: <002301c3769d$b988d000$f101000a@IT001>

* 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