8.6. Boolean Type

8.6. Boolean Type

8.6. Boolean values

PostgreSQL provides the standard SQL type boolean; see Table 8.19. The boolean type can have several states: “true”, “false”, and a third state, “unknown”, which is represented by the SQL null value.

PostgreSQL provides the standard SQL type boolean: Table 8.19. boolean type can have the following states: "true", "false" and "unknown", "unknown" indicates a null value in SQL.

 

Valid literal values for the “true” state are:

"True" status is available:

 

TRUE

't'

'true'

'Y'

'yes'

'on'

'1'

 

For the “false” state, the following values can be used:

"False" status is available:

 

FALSE

'f'

'false'

'n'

'no'

'off'

'0'

 

Leading or trailing whitespace is ignored, and case does not matter. The key words TRUE and FALSE are the preferred (SQL-compliant) usage.

The first ignores spaces or trailing spaces and is not case sensitive. Of course, it is best to use keywords TRUE and FALSE (conforms to the SQL standard).

 

Example 8.2 shows that boolean values are output using the letters t and f.

8.2 shows an example of using the letters t and f outputs a Boolean value.

 

Example 8.2. Using the boolean Type

 

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 | It is

f | is not

SELECT * FROM test1 WHERE a;

a | b

---+---------

T | It is

 

Published 341 original articles · won praise 54 · views 880 000 +

Guess you like

Origin blog.csdn.net/ghostliming/article/details/104662742