randomize timestamp in postgresql

December 21st, 2009

The following may be useful for test data or if you need to get data into a table that has a timestamp column included in the primary key requirement.

Create a function that will allow you to specify a random number range (taken from the http://wiki.postgresql.org/wiki/Random_Range):


CREATE OR REPLACE FUNCTION random(numeric, numeric
RETURNS numeric AS $$
SELECT ($1 + ($2 - $1) * random())::numeric;
$$ LANGUAGE 'sql' VOLATILE;

I then used it to generate a range of timestamps for today:
select timestamp '2009-12-21' + random(0,86400) * interval '1 second' as timestamp;
				

Building and Configuring a Central Logging Server with syslog-ng

September 19th, 2006

End of Life times (Fedora Core 1, 2, Red Hat Linux 7.3, 9)

July 26th, 2006

Subversion and keyword substitution

July 24th, 2006

Faster software RAID reconstruction

July 23rd, 2006

Mac OS X System Startup

July 7th, 2006

Mount a firewire drive at boot on OS X

June 28th, 2006

Is this the Last Day of the Month?

April 12th, 2006

Migrate RHEL to CentOS

April 11th, 2006

Remote Conversion to RAID-1 for Crazy Sysadmins

February 16th, 2006