Sunday, 12 May 2019

How to add a column in every table of a database?

do $$
declare
    selectrow record;
begin
for selectrow in
    select
      'ALTER TABLE '|| T.mytable || ' ADD COLUMN IF NOT EXISTS insert_by bigint' as script
   from
      (
        select tablename as mytable from  pg_tables where schemaname  ='public' --your schema name here
      ) t
loop
execute selectrow.script;
end loop;
end;
$$;




PostgreSQL: How to add a column in every table of a database?

No comments:

Post a Comment