SELECT 
    'CREATE TABLE ' || schemaname || '.' || tablename || E'\n(\n' ||
    string_agg(column_definition, E',\n') || E'\n);\n'
FROM (
    SELECT 
        schemaname,
        tablename,
        column_name || ' ' || data_type ||
        CASE 
            WHEN character_maximum_length IS NOT NULL THEN '(' || character_maximum_length || ')'
            ELSE ''
        END ||
        CASE 
            WHEN is_nullable = 'NO' THEN ' NOT NULL'
            ELSE ''
        END as column_definition
    FROM pg_catalog.pg_tables t
    JOIN information_schema.columns c 
        ON t.schemaname = c.table_schema 
        AND t.tablename = c.table_name
    WHERE schemaname != 'pg_catalog'  
    	and schemaname != 'information_schema'-- Replace with your schema name
) t
GROUP BY schemaname, tablename;
