From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Łukasz Brodziak <l(dot)brodziak(at)outlook(dot)com> |
Cc: | PostgreSQL <pgsql-admin(at)postgresql(dot)org> |
Subject: | Re: Adding same column to several tables. |
Date: | 2016-06-16 20:28:12 |
Message-ID: | CAKFQuwbJwqo7iuA7temhHHo-8cFLMfmKZxzoZ8XMWdiMOwt8-Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
On Thu, Jun 16, 2016 at 4:19 AM, Łukasz Brodziak <l(dot)brodziak(at)outlook(dot)com>
wrote:
> Hello,
>
> I have a function to add column to all tables from the list:
> do
> $$
> declare
> relnam pg_class.relname%TYPE;
> kur cursor for select c.relname
> from pg_class as c
> inner join pg_attribute as a on a.attrelid = c.oid
> where a.attname = 'some_id' and c.relkind = 'r';
> begin
> open kur;
> LOOP
> Fetch kur into relnam;
> exit when not found;
> EXECUTE 'ALTER TABLE '|| relnam|| ' add column another_id integer
> default -1';
> END LOOP;
> close kur;
> END;
> $$
>
> I have 22 table names returned by the query used by cursor. Whe I run the
> function it executes for 1.5 minutes. Is there a way of doing it faster?
>
I suspect your default is the cause of the problem.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | hubert depesz lubaczewski | 2016-06-17 07:58:22 | Re: Adding same column to several tables. |
Previous Message | Łukasz Brodziak | 2016-06-16 08:19:10 | Adding same column to several tables. |