I'm trying recreate a table's structure inside a function by using some dynamic SQL.
EXECUTE 'CREATE TABLE ' || my_table_name || '_bk' ||
' (like ' || _my_table_name || ')';
That will be similar to:
CREATE TABLE my_table_bk
(like my_table);
But I need to discard all constraints. Using EXCLUDING CONSTRAINTS
in the Like Options, it still copy the NOT NULL Constraints (Documentation confirms this behavior):
CREATE TABLE my_table_bk
(like my_table EXCLUDING CONSTRAINTS);
The question is, how can I recreate the table structure without the NOT NULL constraints, or, in alternative, remove all NOT NULL constraints in a table?