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

Why 't' and 'f' instead of TRUE and FALSE

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

Problem

Why does PostgreSQL return 't' and 'f' instead of TRUE and FALSE?

The documentation itself advises us to use TRUE and FALSE when inserting boolean values or making comparisons, but returns a different set of values when selecting the value from the database.

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


Is there a reason for this behavior? Have the PostgreSQL commmunity ever tried to change that?

Solution

PostgreSQL does not return these instead of boolean values. It is some clients (for example, psql and pgAdminIII) which represents TRUE with t and FALSE with f - try the same query in another client and you will see something else. See, for example, what DBVisualizer gives you:

I guess the reason for showing t and f is simply sparing space in a command-line client that lacks horizontal scrolling abilities.

Note: I am in no way affiliated to DbVis Software.

Context

StackExchange Database Administrators Q#115234, answer score: 17

Revisions (0)

No revisions yet.