Category Archives: sql

A very simple persistent consumer-producer queue

This is my take on implementing a very simple persistent consumer-producer style queue using database table. The producers insert records to the table and consumers process them. There can be many producers and/or consumers working simultaneously. They can be separate processes or threads. There is no explicit locking.

Continue reading

Table transposition in SQL

Here’s a cool SQL trick for doing a partial transposition of a table:

select id,

  max(case when language_id = 1 then text else null end) pl_text,

  max(case when language_id = 2 then text else null end) en_text

from translations

group by id;

Continue reading