A beginner’s guide to natural and surrogate database keys

Types of primary keys All database tables must have one primary key column. The primary key uniquely identifies a row within a table therefore it’s bound by the following constraints: UNIQUE NOT NULL IMMUTABLE When choosing a primary key we must take into consideration the following aspects: the primary key may be used for joining other tables through a foreign key relationship the primary key usually has an associated default index, so the more compact the data type the less space the index will take the primary key assignment must ensure uniqueness… Read More

The data knowledge stack

Concurrency is not for the faint-hearted We all know concurrency programming is difficult to get it right. That’s why threading tasks are followed by extensive design and code review sessions. You never assign concurrent issues to inexperienced developers. The problem space is carefully analyzed, a design emerges and the solution is both documented and reviewed. That’s how threading related tasks are usually addressed. You will naturally choose a higher level abstraction since you don’t want to get tangled up in low-level details. That’s why the java.util.concurrent is usually better (unless you build… Read More

Time to break free from the SQL-92 mindset

Are you stuck in the 90s? If you are only using the SQL-92 language reference, then you are overlooking so many great features like: Window Functions PIVOT MERGE INSTEAD OF triggers Some test data In my previous article I imported some CSV Dropwizard metrics into PostgreSQL for further analysis.

How to import CSV data into PostgreSQL

Introduction Many database servers support CSV data transfers and this post will show one way you can import CSV files to PostgreSQL. SQL aggregation rocks! My previous post demonstrated FlexyPool metrics capabilities and all connection related statistics were exported in CSV format. When it comes to aggregation tabular data SQL is at its best. If your database engine supports SQL:2003 windows functions you should definitely make use of this great feature.

JOOQ Facts: SQL functions made easy

Introduction The JDBC API has always been cumbersome and error-prone and I’ve never been too fond of using it. The first major improvement was brought by the Spring JDBC framework which simply revitalized the JDBC usage with its JdbcTemplate or the SqlFunction classes, to name a few. But Spring JDBC doesn’t address the shortcoming of using string function or input parameters names and this opened the door for type-safe SQL wrappers such as jOOQ. JOOQ is the next major step towards a better JDBC API and ever since I started using it… Read More