DB/PostgreSQL

[PostgreSQL] PostgreSQL의 boolean 타입에 대해서 알아보자.

빙기때침식곡 2022. 6. 17. 00:43
반응형

SQL의 standard 타입 'boolean'

 

boolean 타입은 "true" 또는 "false"의 값을 갖는다.

 

기본적으로 true, false를 갖지만 아래와 같이 표현할 수 있다.

 

 - true : true, y, on, 1

 - false : false, n, off, 0

 

'yes'::boolean -> true

'no'::boolean -> false

 

 

 

CREATE TABLE test1 (a boolean, b text);
INSERT INTO test1 VALUES (TRUE, ‘sic est’);
INSERT INTO test1 VALUES (FALSE, ‘non est’);
SELECT * FROM test1;

a | b

—+---------

t | sic est

f | non est

 

 

SELECT * FROM test1 WHERE a;

a | b

–+----------

t | sic est

 

 

CREATE TABLE booltest (flag boolean);
INSERT INTO booltest VALUES (TRUE), ('no'), ('0'), ('yes'), (FALSE);
SELECT * FROM booltest;

flag

------

t

f

f

t

f

 

 

 

REFERENCES

 

PostgreSQL : Documentation: 13: PostgreSQL 13.7 Documentation

 

postgrespro.com

 

반응형