snippetsqlMajor
How to toggle a boolean field by sql in postgresql?
Viewed 0 times
postgresqlfieldbooleansqlhowtoggle
Problem
There is a field
I want to write a sql to update that table, to toggle the value of show. If it's
Is it possible?
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?
Solution
This will do:
so a value of
SET show = NOT showso a value of
TRUE becomes FALSE,FALSE becomes TRUE,UNKNOWN (NULL) stays UNKNOWN.Code Snippets
SET show = NOT showContext
StackExchange Database Administrators Q#15768, answer score: 27
Revisions (0)
No revisions yet.