Skip to content

Instantly share code, notes, and snippets.

@samba
Created November 17, 2015 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samba/a1c8448e5ee699e6150e to your computer and use it in GitHub Desktop.
Save samba/a1c8448e5ee699e6150e to your computer and use it in GitHub Desktop.
Redshift Compatibility Functions
/* 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