-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ammon Smith
committed
Jun 22, 2019
1 parent
8fea90a
commit 56a0d1a
Showing
1 changed file
with
11 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- Helper function to convert Discord IDs into snowflakes purely within Postgres | ||
-- Equivalent in Python: | ||
-- datetime.utcfromtimestamp(((id >> 22) + DISCORD_EPOCH) / 1000) | ||
-- where DISCORD_EPOCH is 1420070400000 | ||
|
||
CREATE FUNCTION snowflake_time(id bigint) | ||
RETURNS TIMESTAMP WITH TIME ZONE | ||
LANGUAGE SQL | ||
AS 'SELECT to_timestamp(((id >> 22) + 1420070400000) / 1000) AS timestamp' | ||
RETURNS NULL ON NULL INPUT | ||
IMMUTABLE; |