Re: simple update on boolean - Mailing list pgsql-general

From Obe, Regina
Subject Re: simple update on boolean
Date
Msg-id 53F9CF533E1AA14EA1F8C5C08ABC08D202E01786@ZDND.DND.boston.cob
Whole thread Raw
In response to Re: simple update on boolean  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
List 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@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Ivan Sergio
Borgonovo
Sent: Thursday, December 06, 2007 10:19 AM
To: pgsql-general@postgresql.org
Subject: Re: [GENERAL] simple update on boolean

On Thu, 06 Dec 2007 14:53:13 +0100
Cedric Boudin <cedric@dreamgnu.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.


pgsql-general by date:

Previous
From: Ivan Sergio Borgonovo
Date:
Subject: Re: simple update on boolean
Next
From: "Abraham, Danny"
Date:
Subject: Question in dblink