Aaron O. Ellis


Fixing the Postgres Query Planner with enable_seqscan = off

If you’re querying a table with a small number of rows in Postgres, your query will most likely use a “sequential scan”, which scans the entirety of the table to find your result. This is true even when tables have an index for the field or fields you’re querying.

Using Postgres Schemas

Schemas are a shockingly underappreciated feature of relational databases. With minimal overhead, they enable segmentation and isolation of tables within a database.

If you are interested in using schemas with Postgres, I recommend starting with the official documentation’s fantastic introduction. Although I will reiterate some of the introduction below, I will mainly focus on the exceptional behavior and issues that arise when using schemas.

Aggregation with django-filter via Proxy Models

The django-filter package adds a quick way to add URL parameter driven filtering to existing Django database models. For example, take the following model:

We can then use django-filter to quickly create a FilterSet class that wraps the above database model:

Python datetime.utcnow() Considered Harmful

The Python datetime.utcnow() classmethod is harmful and should be replaced with datetime.now(timezone.utc).

What makes utcnow() so dangerous? Although the function gives the correct time in the UTC timezone, the returned datetime does not include a timezone.

New York Times Misleads on COVID-19 Cases in Small U.S. Counties

Last week, the New York Times published an excellent series of visualizations tracking the COVID-19 outbreak in rural areas across the United States. At the very end of the article, however, they added a misleading table of the counties with the highest average daily case rates. The intent was to show that the most recent cases are hitting rural areas harder than urban and suburban areas of the country, and they did so by highlighting the counties with less than 10,000 people.

View all articles →