Skip to content

Instantly share code, notes, and snippets.

@andrewbt
Created September 19, 2017 06:49
Show Gist options
  • Select an option

  • Save andrewbt/066cc1deef3173351f9d6b358b93d78b to your computer and use it in GitHub Desktop.

Select an option

Save andrewbt/066cc1deef3173351f9d6b358b93d78b to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION random_time_from_year_string(y TEXT)
RETURNS timestamp AS $$
select (y || '-01-01 00:00:00')::timestamp +
random() * ((y || '-12-31 23:59:59')::timestamp -
(y || '-01-01 00:00:00')::timestamp);
$$ LANGUAGE SQL IMMUTABLE STRICT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment