Created
November 17, 2015 23:32
-
-
Save samba/a1c8448e5ee699e6150e to your computer and use it in GitHub Desktop.
Redshift Compatibility Functions
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
/* Functions available in Redshift that can be emulated in Postgres for compatibility. | |
* This is most applicable when a schema needs to be migrated into a (local) PostgreSQL | |
* environment for modeling/development. As Redshift is derived from PostgreSQL, many | |
* DBA and related modeling tools designed for PostgreSQL are _not quite_ viable for | |
* use with Redshift. These functions attempt to augment native PostgreSQL to allow | |
* Redshift SQL to run in other Postges environments. | |
* I'll update this periodically with additional functions as needed. | |
*/ | |
CREATE FUNCTION public.getdate() returns timestamptz | |
stable language sql as 'select now()'; | |
CREATE FUNCTION date_diff(text, timestamp, timestamp) returns integer as $$ | |
DECLARE | |
span interval := age($2, $3); | |
BEGIN | |
select date_part($1, span); | |
END | |
$$ language plpgsql; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment