Re: Adding same column to several tables.

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Adding same column to several tables.
Дата
Msg-id CAKFQuwbJwqo7iuA7temhHHo-8cFLMfmKZxzoZ8XMWdiMOwt8-Q@mail.gmail.com
обсуждение исходный текст
Ответ на Adding same column to several tables.  (Łukasz Brodziak <l.brodziak@outlook.com>)
Список pgsql-admin
On Thu, Jun 16, 2016 at 4:19 AM, Łukasz Brodziak <l.brodziak@outlook.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.

В списке pgsql-admin по дате отправления:

Предыдущее
От: Łukasz Brodziak
Дата:
Сообщение: Adding same column to several tables.
Следующее
От: hubert depesz lubaczewski
Дата:
Сообщение: Re: Adding same column to several tables.