Categories
josephscott

Implementing a Queue in SQL

Greg’s Implementing a queue in SQL (Postgres version) is an interesting exercise. The goal was to implement a simple queue that can be managed via SQL. The example is a simple first in, first out (FIFO) queue, with a limit of 5 items.

Two methods are demonstrated to accomplish this, the first one makes use of the PostgreSQL Rules and is very short. The second one is a little bit longer and uses a PL/pgSQL function as a trigger. One advantage of the second method is that it lets you know how many rows in your queue were recycled. Both methods require only one table.

There’s also a queue in MySQL article as well.

Is it practical to implement FIFO queues in a DBMS? Maybe not, but it is a good example of thinking outside the box.

Leave a Reply

Your email address will not be published. Required fields are marked *