Skip to content

Instantly share code, notes, and snippets.

@wbrframe
Last active August 8, 2019 09:57
Show Gist options
  • Save wbrframe/092c9de78b8f9c68825b7d018e90fd92 to your computer and use it in GitHub Desktop.
Save wbrframe/092c9de78b8f9c68825b7d018e90fd92 to your computer and use it in GitHub Desktop.
Generate microseconds for exists dates that without microseconds
# For example, you store dates in the type `timestamp with timezone`:
2019-08-04 11:13:17+00
# This query generates randomly microseconds for a date:
UPDATE <table> SET <field> = TO_TIMESTAMP(replace(to_char(<field>, 'YYYY-MM-DD HH24:MI:SS.SS%m%OF'), '%m%', (floor(random()*(10000-1+1))+1)::text), 'YYYY-MM-DD HH24:MI:SS.US')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment