How to get the ddl of a table in Redshift database

Run the below query to obtain the ddl of a table in Redshift database.

select * from admin.v_generate_tbl_ddl where schemaname ='nameofschema' and tablename='nameoftable';

If the view v_generate_tbl_ddl is not in your admin schema, you can create it using below sql provided by the AWS Redshift team.

https://github.com/awslabs/amazon-redshift-utils/blob/master/src/AdminViews/v_generate_tbl_ddl.sql

See also  How to create a table in Redshift database