Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Postgres accepts 'tru' and 'fals' for boolean values (github.com/postgres)
1 point by joelanman on June 25, 2024 | hide | past | favorite | 4 comments


I 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.


The 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...

which uses

https://github.com/postgres/postgres/blob/master/src/backend...


> Valid values are: true, false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.


oh neat, so t, f, y, n, on, of, 1, 0




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: