HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMajor

How to toggle a boolean field by sql in postgresql?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlfieldbooleansqlhowtoggle

Problem

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?

Solution

This will do:

SET show = NOT show


so a value of

TRUE becomes FALSE,

FALSE becomes TRUE,

UNKNOWN (NULL) stays UNKNOWN.

Code Snippets

SET show = NOT show

Context

StackExchange Database Administrators Q#15768, answer score: 27

Revisions (0)

No revisions yet.