Info

You are currently browsing the archives for the Postgres category.

Calendar
March 2010
M T W T F S S
« Mar    
1234567
891011121314
15161718192021
22232425262728
293031  
Categories
Links

Archive for the Postgres Category

Selecting random rows from a table

The question of how to select some random items from a table is one that comes up fairly often in the IRC channel (and as the subject of blog posts, such as this one from depesz).
While there is a simple solution of this form (let’s assume for now that we want to select 5 uniformly random rows from table “items”):

select * from items order by random() limit 5;

this is unfortunately slow if the table has more than a small number of rows. It is possible to do far better, though there aren’t really any perfect solutions that don’t resort to procedural logic in some way. Let’s start by looking at how to do better in plain SQL.
Read the rest of this entry »

Reading XML files into the database

This came up as a question on IRC: how to read an XML file on the server into a table column?

Read the rest of this entry »

UUID generation for PostgreSQL 8.3 on FreeBSD

A couple of weeks ago I whomped up a quick module in response to someone on IRC who was unable to get contrib/uuid-ossp working on FreeBSD (which turns out to be due to a nasty conflict between misc/ossp-uuid and libc).

I’ve now put it up on PGFoundry, and the initial release can be found here:

http://pgfoundry.org/projects/uuid-freebsd/

|