Random String in PostgreSQL

The Problem

Last time I wrote about the common problem with the random function. PostgreSQL has got only the random() function, no function like random(from, to) or random(length) which returns random text of given length.

This time I just need a function that returns a random text of given length which can be used like this: SELECT random_text(42). The random text will be used as a slug in a web application, so I need only numbers and letters, and let’s also uppercase all.

Let’s create a PL/pgSQL procedure for returning a random text with given length. Continue reading

PostgreSQL 9.1 Best Features

PostgreSQL 9.1 is almost out. That’s great. There are many nice features, so I will mention some most important for me:

1. Per column collation.

This is the feature I was waiting for a long time. I’ve written some entries about the problems with collation. Now all of them has gone… from now on the collaction can be set per column, domain, index or even expression. I’ve written some posts about the problems with collations in postgresql: postgresql collation part 1 postgresql collation part 2 postgresql collation 8.4. I think these problems will magically disappear in 9.1. Really cool. Continue reading

Django Admin Panel Weirdness

Django Has ORM

I’ve started clicking a small Django application. It uses PostgreSQL (that’s obvious). My local PostgreSQL databases log all queries, so I’ve clicked a little bit and checked what queries were sent to database.

The whole application has a simple model with class Tag (for tags of course). I’ve configured that to show in the admin application. I’ve added two tags, deleted them… and the PostgreSQL log file filled with all sorts of strange lines.
Continue reading