Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to duplicate a Redshift table schema?

I'm trying to duplicate a Redshift table including modifiers.

I've tried using a CTAS statement and for some reason that fails to copy modifiers like not null

create table public.my_table as (select * from public.my_old_table limit 1);

There also doesn't seem to be a way to alter the table to add modifiers after creating the table which leads me to believe that there isn't a way to duplicate a Redshift table schema except by running the original create table statement vs the CTAS statement.

like image 718
SomeGuyOnAComputer Avatar asked Jun 01 '17 23:06

SomeGuyOnAComputer


People also ask

How do you duplicate a table?

Right-click the table you wish to duplicate, point to Script Table as, then point to CREATE to, and then select New Query Editor Window. Change the name of the table. Remove any columns that are not needed in the new table. Select Execute to create the new table.


1 Answers

According to the docs you can do

CREATE TABLE my_table(LIKE my_old_table);
like image 165
salient Avatar answered Nov 04 '22 06:11

salient