← Back to PostgreSQL Course | Chapter 3: Data Types | Lesson 3 of 7

BOOLEAN टाइप

boolean true, false, या unknown (NULL) store करता है।

In this page:

  1. BOOLEAN
Syntax
sql
column_name boolean DEFAULT false
WHERE column_name IS TRUE

BOOLEAN

PostgreSQL boolean input की तरह TRUE, FALSE, t, f, yes, no, on, off, 1, और 0 accept करता है और psql में t और f display करता है। Conditions सीधे WHERE में इस्तेमाल हो सकती हैं, और IS TRUE, IS FALSE, और IS NOT DISTINCT FROM NULL को safely handle करते हैं।

Booleans AND, OR, और NOT से combine होते हैं।

Note: एक boolean column true, false, या NULL हो सकता है, इसलिए decide करें कि NULL allowed है या नहीं।

उदाहरण: BOOLEAN

bash
shop=# CREATE TABLE tasks (id serial PRIMARY KEY, title text, done boolean DEFAULT false);
shop=# INSERT INTO tasks (title, done) VALUES ('write', true), ('test', false), ('ship', NULL);
shop=# SELECT title, done FROM tasks;
 title | done
-------+------
 write | t
 test  | f
 ship  |
shop=# SELECT title FROM tasks WHERE done;
 title
-------
 write
shop=# SELECT title FROM tasks WHERE done IS NOT TRUE;
 title
-------
 test
 ship

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. yes/no को text की तरह store करना
  2. यह भूल जाना कि NULL एक third state है
  3. column को सीधे इस्तेमाल करने की बजाय = TRUE से compare करना
चैप्टर सारांश
  • Values true, false, और NULL
  • कई input spellings accepted हैं
  • IS TRUE और IS NOT DISTINCT FROM इस्तेमाल करें
  • WHERE में column सीधे इस्तेमाल करें
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.