Home / Companies / Knock / Blog / Post Details
Content Deep Dive

How to ORDER BY using the contents of a column in Postgres

Blog post from Knock

Post Details
Company
Date Published
Author
Brent Anderson
Word Count
1,192
Company Posts That Month
2
Language
English
Hacker News Points
-
Post removed?
No
Summary

Knock enhances team communication by efficiently managing notifications, with a key feature being the ability to batch multiple notifications into a single, timely message. This batching process involves creating variables that summarize the batch, such as item count and unique user count, and providing an array of the first ten items for detailed information. A customer request led to a challenge of providing the last ten activities instead, which was tackled using advanced SQL window functions in Postgres. The solution involved using CASE statements within ORDER BY clauses to selectively sort data either in ascending or descending order based on user settings, thus allowing different ordering for different batches within a single query. This approach, though slightly more complex and costly in terms of query performance, ultimately resulted in more maintainable and understandable code, showcasing how SQL's flexibility can be harnessed to meet specific business needs.

Trends Found in this Post

No tracked trend matches for this post yet.

Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.