Skip to content

Instantly share code, notes, and snippets.

@tamiroze
Last active February 16, 2021 03:13
Show Gist options
  • Save tamiroze/30cca624b8098c62b26b0b9a8ac30059 to your computer and use it in GitHub Desktop.
Save tamiroze/30cca624b8098c62b26b0b9a8ac30059 to your computer and use it in GitHub Desktop.
Generate redshift ddl
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(
table_name, schema_name
)
pg_cursor.execute(sql)
ddl = pg_cursor.fetchall()
pg_cursor.close()
print "ddl:", ddl
return ddl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment