Re: simple update on boolean

From: "Obe, Regina" <robe(dot)dnd(at)cityofboston(dot)gov>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: simple update on boolean
Date: 2007-12-06 15:20:51
Message-ID: 53F9CF533E1AA14EA1F8C5C08ABC08D202E01786@ZDND.DND.boston.cob
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


You could use a COALESCE instead of a case statement for simple case
like this. The below will treat a NULL as false and then when you do
not it becomes true. So NULLS will be set to true

UPDATE boolean_column SET boolean_column = NOT COALESCE(boolean_column,
false)

hope that helps,
Regina

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Ivan Sergio
Borgonovo
Sent: Thursday, December 06, 2007 10:19 AM
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] simple update on boolean

On Thu, 06 Dec 2007 14:53:13 +0100
Cedric Boudin <cedric(at)dreamgnu(dot)com> wrote:

> > What if boolean_column is NULL?
> >
> > btw set bolean_column= not bolean_column works "as expected".
> >
> > template1=# select (not 't'::boolean),(not 'f'::boolean),(not
> > NULL::boolean);
> >
> > ?column? | ?column? | ?column?
> > ----------+----------+----------
> > f | t |
> > (1 riga)

> If it was null before it has to be null afterwards (IMHO).
> If you don't want to have null,
> take care of it somewhere else but not here.

That is the "as expected" part.

The "case" case, other than being more verbose, do more than what I
would expect since all NULL are converted to t.

template1=# select case when NULL then 'f'::boolean else 't'::boolean
end;

case
------
t
(1 riga)

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Abraham, Danny 2007-12-06 15:29:20 Question in dblink
Previous Message Ivan Sergio Borgonovo 2007-12-06 15:19:19 Re: simple update on boolean