3 ms·
Postgres accepts 'tru' and 'fals' for boolean values
- dflock 2y ago> Valid values are: true, false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
- qbxk 2y agooh neat, so t, f, y, n, on, of, 1, 0
- foldr 2y agoI was a bit confused by this claim initially, but I think the point is that Postgres will evaluate e.g. the following expression to TRUE: select 'tru' or 'fals'; If you change the strings to e.g. 'bar' and 'baz', then you'll see the expected kind of error. Postgres will parse any non-zero prefix of 'true' or 'false' as a boolean in a boolean conversion context.
- anarazel 2y agoThe linked code is actually just for the variables in psql (the commandline tool). For the code parsing input to the SQL-level bool datatype, it's https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/bool.c#L126 https://github.com/postgres/postgres/blob/master/src/backend... which uses https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/bool.c#L36 https://github.com/postgres/postgres/blob/master/src/backend...