PostgreSQL: How to insert random BOOLEAN

This is just a quick tip, I did some searches and couldn’t find a solution to insert random Boolean values into postgres table.

In fact, it’s quite simple:

INSERT INTO table(
 id, boolean_value)
 VALUES (1, cast(cast(random() as integer) as boolean));

 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *