Redshift | Snowflake |
---|---|
json_extract_path_text (properties,'name') | parse_json(properties):name |
select json_extract_array_element_text('[111,112,113]', 2); | select parse_json('[111,112,113]')[2]; |
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
select * | |
from information_schema.tables | |
where table_name= upper('table_name'); | |
# Instead make sure you send the string in UPPER case. Dont use the upper function. | |
select * | |
from information_schema.tables | |
where table_name= 'TABLE_NAME'; |
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
show parameters like '%TIMEZONE%' in account; | |
#change your account setup in case you want a different timezone | |
alter account SET TIMEZONE = 'UTC'; |
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
copy into {0}{1} | |
from {2} | |
truncatecolumns = true | |
file_format = | |
( | |
field_optionally_enclosed_by='"' | |
escape_unenclosed_field='NONE' | |
type = csv | |
TRIM_SPACE = TRUE | |
field_delimiter = '|' |
Redshift | Snowflake |
---|---|
DELETE customers | DELETE from customers |
Redshift | Snowflake |
---|---|
select GETDATE() | select CURRENT_TIMESTAMP() |
select TRUNC(CURRENT_TIMESTAMP()) | select DATE_TRUNC(DAY,CURRENT_TIMESTAMP()) |
select SYSDATE | select TO_TIMESTAMP_NTZ(CONVERT_TIMEZONE('UTC',CURRENT_TIMESTAMP())) |
select DATE(CURRENT_TIMESTAMP()) | select TO_DATE(CURRENT_TIMESTAMP()) |
date_time_utc > GETDATE() - 7 | date_time_utc > dateadd('DAY', -7, TO_TIMESTAMP_NTZ(LOCALTIMESTAMP)) |
select coalesce('a') | select coalesce('a', 'b') --you will get error message if you specify only one argument "SQL compilation error: error line 1 at position 7 not enough arguments for function [COALESCE('a')], expected 2, got 1" |
DISTSTYLE | not used |
DISTKEY | not used |
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
def run_data_migration(self, schema_name, table_name): | |
self.logger.info("querying redshift metadata") | |
pg_conn = pg.connect(cfg.REDSHIFT_DB_URL) | |
print "pg_conn:", pg_conn | |
pg_cursor = pg_conn.cursor() | |
if table_name != "none": | |
sql = """ |
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
#!/usr/bin/python | |
# $Id: $ | |
# Converts Oracle, SQL-Server, and other DDL to Snowflake DDL | |
def usage(): | |
print """\ | |
# Usage: sql2sf.py input-file [output-file] | |
""" |
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
def get_table_ddl(self, table_name, schema_name): | |
self.logger.info("querying redshift metadata") | |
pg_conn = pg.connect(cfg.REDSHIFT_DB_URL) | |
pg_cursor = pg_conn.cursor() | |
sql = """ | |
select ddl | |
from vw_admin_generate_table_ddl | |
where tablename='{0}' | |
and schemaname='{1}' """.format( |