TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Postgres accepts 'tru' and 'fals' for boolean values

1 pointsby joelanman11 months ago

3 comments

foldr11 months ago
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:<p><pre><code> select &#x27;tru&#x27; or &#x27;fals&#x27;; </code></pre> If you change the strings to e.g. &#x27;bar&#x27; and &#x27;baz&#x27;, then you&#x27;ll see the expected kind of error. Postgres will parse any non-zero prefix of &#x27;true&#x27; or &#x27;false&#x27; as a boolean in a boolean conversion context.
anarazel11 months ago
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&#x27;s<p><a href="https:&#x2F;&#x2F;github.com&#x2F;postgres&#x2F;postgres&#x2F;blob&#x2F;master&#x2F;src&#x2F;backend&#x2F;utils&#x2F;adt&#x2F;bool.c#L126">https:&#x2F;&#x2F;github.com&#x2F;postgres&#x2F;postgres&#x2F;blob&#x2F;master&#x2F;src&#x2F;backend...</a><p>which uses<p><a href="https:&#x2F;&#x2F;github.com&#x2F;postgres&#x2F;postgres&#x2F;blob&#x2F;master&#x2F;src&#x2F;backend&#x2F;utils&#x2F;adt&#x2F;bool.c#L36">https:&#x2F;&#x2F;github.com&#x2F;postgres&#x2F;postgres&#x2F;blob&#x2F;master&#x2F;src&#x2F;backend...</a>
dflock11 months ago
&gt; Valid values are: true, false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
评论 #40792361 未加载