Ikai Lan says

I say things!

Archive for August 2017

Recreating the create statement for a Redshift Spectrum table

(I don’t have time to write my usual long posts, so here’s a quick one to try to get me back into the habit of technical blogging)

All of the information to reconstruct the create statement for a Redshift Spectrum table is available via the views svv_external_tables and svv_external_columns views. Reconstructing the create statement is slightly annoying if you’re just using select statements. SO: Here is a quick and dirty Python script that does an okay but imperfect job of this:

Take and modify as needed for your needs. I even prepended an MIT license it for you overly cautious big company cats that may need to run it by legal or whatever.

Another cool approach if you’re using Parquet would be to use either parquet or fastparquet┬áto┬áread the schema from the parquet file in S3 and generate a create table statement based on that. I didn’t write that tool, but if you do, go ahead and let me know and I’ll link to you.

Advertisements

Written by Ikai Lan

August 16, 2017 at 10:51 am