There is a field show
which is a boolean
type in postgesql.
I want to write a sql to update that table, to toggle the value of show. If it's true
, it becomes false
, if it's false
, it becomes true
.
Is it possible?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.
Sign up to join this communityThere is a field show
which is a boolean
type in postgesql.
I want to write a sql to update that table, to toggle the value of show. If it's true
, it becomes false
, if it's false
, it becomes true
.
Is it possible?
This will do:
SET show = NOT show
so a value of
TRUE
becomes FALSE
,
FALSE
becomes TRUE
,
UNKNOWN
(NULL
) stays UNKNOWN
.
TRUE
and FALSE
, a variation on UNKNOWN
was appropriate :)
– ypercubeᵀᴹ
Mar 29 '12 at 6:38
The following will turn FALSE
or NULL
to TRUE
, and TRUE
to FALSE
:
UPDATE tablename SET fieldname = NOT COALESCE( fieldname, 'f' ) WHERE keyvalue = ?;