Skip to content
HomeVideosBooksBlogs
AllTop postsTopics
Podcasts
HistoryListsWatch laterLiked videosFollowing

The videos, books, blogs and podcasts Hacker News keeps recommending, all in one place.

VideosBooksBlogsPodcastsAboutPrivacySettings

Data from Hacker News, HackerTube, HackerBooks, HackerBlogs and Open Library. Credits · Not affiliated with Y Combinator.

HomeVideosBooksBlogsPodcasts
Ctrl K
    H

    Haki Benita

    hakibenita.com · Personal blog · on HN since 2019

    Haki Benita writes detailed articles on SQL, PostgreSQL performance, Django, and Python, with practical examples and benchmarks.

    Visit blogRSSHN submissions
    DatabasesProgramming
    What HN says

    Commenters pick up on specifics such as the MERGE tip, cite his SQL tricks for application DBAs, and list him among good personal blogs.

    Stats for nerds
    52HN people shared it
    67linked in comments
    3.6Kstory points
    Apr 2026last shared
    2020people per year2026

    Top posts on HN

    1. 1
      Lesser-known Postgres features
      4 people · 709 points · first shared 2021 · 166 comments on HN
    2. 2
      Practical SQL for Data Analysis
      6 people · 615 points · first shared 2021 · 191 comments on HN
    3. 3
      Simple Anomaly Detection Using Plain SQL
      6 people · 528 points · first shared 2020 · 47 comments on HN
    4. 4
      An unexpected find that freed 20GB of unused index space in PostgreSQL
      3 people · 377 points · first shared 2021 · 78 comments on HN
    5. 5
      Some SQL Tricks of an Application DBA
      4 people · 336 points · first shared 2020 · 68 comments on HN
    6. 6
      Fast Way to Load Data into PostgreSQL Using Python
      3 people · 251 points · first shared 2019 · 29 comments on HN
    7. 7
      The surprising impact of medium-size texts on PostgreSQL performance
      4 people · 189 points · first shared 2020 · 16 comments on HN
    8. 8
      Common Mistakes and Missed Optimization Opportunities in SQL
      2 people · 183 points · first shared 2019 · 66 comments on HN
    9. 9
      How to Get or Create in PostgreSQL
      1 person · 103 points · first shared 2024 · 24 comments on HN
    10. 10
      Exhaustiveness Checking with Mypy
      3 people · 88 points · first shared 2020 · 19 comments on HN

    What HN people wrote when they linked it

    • vanflymenApr 2026

      I've been building in Django for a long time and I love the framework, but some things have always bugged me:

      - Typing is exceptionally painful...and getting proper type safety across a Django project is a fight

      - the ORM leaks throughout your project: it's easy to chain ORM methods in a view, a serializer, a template tag, a Celery task, etc and N+1s end up being difficult to find

      - models become god objects: custom managers, save overrides, signal handlers, computed properties, validation logic, your models attract everything until they're 500 lines of tangled responsibilities.

      - tests become slow over time because you either hit the DB for everything or mock too aggressively: this is because there's no clear encapsulated layers.

      and a ton of other stuff including aesthetics...

      Anyway, the short version of my solution is to push all ORM work into repositories that return Pydantic DTOs. Services get repos via constructor injection and contain pure business logic with zero model imports. Your views become one-liners. Every layer boundary is typed, and each layer is independently testable.

      Some of the opinions:

      - Prefixed ULID primary keys: double-clickable Stripe-style IDs like ord_01jq3v... on every model.

      - Models are dumb but aesthetic: Meta first, fields in a strict order (identifiers, times, status, domain, relations), all indexes and constraints declared explicitly in Meta, zero business logic.

      - Repositories return DTOs, never querysets so the ORM never leaks…

    • dataviz1000May 2021

      Lately, I've been studying machine learning, from point zero, with a focus on time series analysis. Two months in already completed a course on Python and another book on Pandas, several hundreds of hours later in the fourth chapter in a book I paid for on deep learning and time series analysis they provided me with the most important information I needed: there is no evidence deep learning works better than traditional statistical analysis using classical methods like SARIMA and ETS. Sure, great, if an academic is interested in theory hopefully making a breakthrough, however, the rest of us who are interested in applied should stick with the classical methods.

      I was going to write a lot here but I'll keep it short.

      What I discovered is that everything I want to do can best be done in PostgreSQL. It's one thing to do data analysis in a Python notebook and another in an environment that works dynamically on a server. My first guess was to do the heavy lifting in Python with Numpy, Pandas, and machine learning and have the node server -- instead of Django and if I'm learning a new web framework it will be Phoenix -- execute the Python scripts through stdin / stdout. Since started I learned that I don't need machine learning and that I can do the calculations inside PostgreSQL sometimes orders of magnitude faster than in Python.

      I'm using TimescaleDB which provides the postgresSQL time_bucket() function and with chunks should scale very well. First I tried to integrate it…

    • bkovacevJan 2025

      Old is a harsh word, maybe mature would be a better fit, not everything new and shiny is gold, and yet not everything old sucks.

      Not arguing here about types and Pydantic being faster than the built in ModelSerializers. However, for serializer speed improvements and performance in DRF I would advise dropping ModelSerializers and either going for Serializers or plain dict. Haki Benita has a beautiful article on that [0]. I was able to accomplish sub 200 response times on a fairly large response from tables that had tens of millions of records.

      I think you have no objective reason other than your styling and rather personal preference for function based views?

      [0] - https://hakibenita.com/django-rest-framework-slow

    • gavinrayNov 2021

      I want to stress the importance of not using

      id int SERIAL

      If you are on a somewhat recent version of postgres, please do yourself a favor and use:

      id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY

      An "identity column", the part here:

      https://hakibenita.com/postgresql-unknown-features#prevent-setting-the-value-of-an-auto-generated-key

      You might think this is trivial -- but SERIAL creates an "owned" (by a certain user) sequence behind the scenes, and so you run into massive headaches if you try to move things around.

      Identity columns don't, and avoid the issue altogether.

      https://www.2ndquadrant.com/en/blog/postgresql-10-identity-columns/

    • msdriggJan 2026

      The most interesting thing for me in this article was the mention of `MERGE` almost in passing at the end.

      > I'm not a big fan of using the constraint names in SQL, so to overcome both limitations I'd use MERGE instead:

      ```
      db=# MERGE INTO urls t
      USING (VALUES (1000004, 'https://hakibenita.com')) AS s(id, url)
      ON t.url = s.url
      WHEN MATCHED THEN UPDATE SET id = s.id
      WHEN NOT MATCHED THEN INSERT (id, url) VALUES (s.id, s.url);
      MERGE 1
      ```

      I use `insert ... on conflict do update ...` all the time to handle upserts, but it seems like merge may be more powerful and able to work in more scenarios. I hadn't heard of it before.

    • simonwJul 2021

      So many - I'm going to share a few that come to mind quickly, rather than agonizing over picking the best possible results.

      Tim Bray: https://www.tbray.org/ongoing/

      Julia Evans: https://jvns.ca/

      Tom MacWright: https://macwright.com/

      Jacob Kaplan-Moss: https://jacobian.org/

      Lea Verou: https://lea.verou.me/

      Will Larson: https://lethain.com/featured/

      Camille Fournier: https://skamille.medium.com/

      Haki Benita: https://hakibenita.com/

      Brandur Leach: https://brandur.org/articles

    Related

    depeszdepesz.com101 people

    Waiting for PostgreSQL 14 – SEARCH and CYCLE clauses

    depesz
    Personal · last shared 2026
    Reinout van Reesreinout.vanrees.org31 people

    PostgreSQL when it is not your job

    Reinout van Rees
    Personal · last shared 2026
    Simon Willison's TILstil.simonwillison.net111 people

    One-liner for running queries against CSV files with SQLite

    Simon Willison's TILs
    Personal · last shared 2026
    Scattered Thoughtsscattered-thoughts.net186 people

    Against SQL

    Scattered Thoughts
    Personal · last shared 2026
    Feldera Blogfeldera.com21 people

    The Pain That Is GitHub Actions

    Feldera Blog
    Company · last shared 2026
    Small Datumsmalldatum.blogspot.com63 people

    The original LSM paper

    Small Datum
    Personal · last shared 2026
    Percona Blogpercona.com327 people

    UUIDs are popular, but bad for performance (2019)

    Percona Blog
    Company · last shared 2026
    Craig Kerstienscraigkerstiens.com101 people

    Give Me Back My Monolith

    Craig Kerstiens
    Personal · last shared 2025