Search Postgresql Archives

Re: simple update on boolean

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 
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@xxxxxxxxxxxxxx
[mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Ivan Sergio
Borgonovo
Sent: Thursday, December 06, 2007 10:19 AM
To: pgsql-general@xxxxxxxxxxxxxx
Subject: Re:  simple update on boolean

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


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux