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.

The case for native assertions in PostgreSQL

1 pointsby gajusabout 1 year ago

1 comment

ttfkamabout 1 year ago
No thank you. One of the things I love about SQL is that it doesn&#x27;t throw. Adding another unit test or two to pgTAP would be my preference over assertions firing unexpectedly.<p>The relations and constraints should establish a contract between application and data. If you are making assumptions on the structure of the data, that goes in a unit test to be run when testing DB schema migrations. Not writing good tests? Well that&#x27;s a root problem that needs to be dealt with. If you can&#x27;t expect proper unit tests of your DB structure, why would you expect proper assertion usage to be better?<p>Then there&#x27;s the issue of app code. Far too many apps have two states: all good and &quot;something bad happened&quot; where bad is one of &quot;database&#x2F;network path went down&quot;, &quot;database schema updated&quot;, or &quot;bad data&quot;. Most software isn&#x27;t written to determine what kind of error, only &quot;something bad happened with the query&quot;. Adding failed assertions to the &quot;something bad happened&quot; list doesn&#x27;t seem to change the equation much to me.<p>If someone changed code to use a multiset instead of a set, would you expect that to be caught by an assertion at runtime or with a test suite during development and integration?